Execution flow What is execution flow n n





![Single alternative n This structure has the form as under if(condition) then [Statements] [end Single alternative n This structure has the form as under if(condition) then [Statements] [end](https://slidetodoc.com/presentation_image_h2/bc08931c06e141e267e7002c7171c720/image-6.jpg)

![Multiple alternative This structure has the following form if (condition-1) then [statement-1] else if(condition-2) Multiple alternative This structure has the following form if (condition-1) then [statement-1] else if(condition-2)](https://slidetodoc.com/presentation_image_h2/bc08931c06e141e267e7002c7171c720/image-8.jpg)

- Slides: 9

Execution flow

What is execution flow? n n The way in which the instructions of the algorithm and their equivalent computer program executes is known as execution flow. To control the execution of the statements and instructions in a particular algorithm we must first understand different techniques of execution flow. These lies in the following three categories n n n Sequential flow Selection or conditional flow Iterative or repetitive flow

Sequential flow n n That type of execution flow in which all instructions are executed in a sequence from top to bottom and there is no repetition is known as sequential flow. The sequence is presented by means of numbered steps.

Sequential flow example The following algorithm is executed sequentially. algorithm : Average This algorithm is used to calculate the average of four integer numbers. Let avg is the float variable where the average stores. n Step-1: [Read data] Read(a, b, c, d) Step-2: [calculate average] avg<- (a+b+c+d)/4 Step-3: [display the result] display(avg) Step-4: [finish] exit Flow chart representation of S-F Step-1 Step-2 Step-3 Step-4

Selection flow n n Selection flow employs a number of conditions which lead to a selection of one or more out of several alternative instructions or modules to be executed. The structure which implement this logic is known as conditional structure or if-structure. There are three types of selection flow. n n n Single alternative Double alternative Multiple alternatives
![Single alternative n This structure has the form as under ifcondition then Statements end Single alternative n This structure has the form as under if(condition) then [Statements] [end](https://slidetodoc.com/presentation_image_h2/bc08931c06e141e267e7002c7171c720/image-6.jpg)
Single alternative n This structure has the form as under if(condition) then [Statements] [end of if structure] Flow chart representation of S -A No Condition 1 if (x ==100) 2 cout << "x is 100"; Yes Statement

Double alternative This structure has the form as follow. if (condition) Then Flow chart representation of D -A [statement-1] else No [statement-2] Condition [end of if structure] n if (x ==100) cout << "x is 100"; else cout << "x is not 100"; Yes Statement-1 Statement-2
![Multiple alternative This structure has the following form if condition1 then statement1 else ifcondition2 Multiple alternative This structure has the following form if (condition-1) then [statement-1] else if(condition-2)](https://slidetodoc.com/presentation_image_h2/bc08931c06e141e267e7002c7171c720/image-8.jpg)
Multiple alternative This structure has the following form if (condition-1) then [statement-1] else if(condition-2) then [statement-2] else if(condition-3) then [statement-3] else [statement-4] [end of if structure] It should be noted that the above logic allows only one statement to be executed out of four(04). n

Iterative or Repetitive flow n n That type of execution flow in which a single statement or block of statements executes repeatedly i: e again and again until a specific condition met is called iterative flow or repetitive flow. Usually loop control structure is used for the implementation of such type of flow in algorithm.