Pseudo Code
There are three types of flow of control
Steps of the algorithm is executed one by one in a sequence.
statement 1
statement 2
statement 3
:
:
Set sum = 0;
Read: x, y;
Set sum = x + y;
Print: sum;
Selection flow are of three types
Single Alternative
if expression then
statements
endif
if x == 10 then
Print: “TEN”;
endif
Double Alternative
if expression then
statement-A
else
statement-B
endif
if x == 10 then
Print: “TEN”;
else
Print: “x is not TEN”;
endif
Note! If the expression is TRUE then statement-A is executed otherwise statement-B is executed.Multiple Alternative
if expression-1 then
statement-1
else if expression-2 then
statement-2
:
:
else if expression-n then
statement-n
else
statement-last
endif
if x == 1 then
Print: “ONE”;
else if x == 2 then
Print: “TWO”;
else if x == 3 then
Print: “THREE”;
else
Print: “x is not 1, 2 and 3”;
endif
Iterative flow are of three types
Method 1
for i = r to s by t do
statements
endfor
for i = 1 to 5 by 1 do
Print: i;
endfor
Method 2
for (i = r; i <= s; i++)
statements
endfor
for (i = 1; i <= 5; i++)
Print: i;
endfor
for i = r to s by t do
statements
endfor
1. Initialize i = r (PROCESS)
2. Is i <= s (DECISION)
if YES then
Execute statements
Calculate i + t and assign it to i
Repeat Step 2 (PROCESS)
else
Stop
while expression do
statements
endwhile
Set i = 1;
while i <=5 do
Print: i;
Set i = i + 1;
endwhile
do
statements
while expression
Set i = 1;
do
Print: i;
Set i = i + 1;
while i <= 5
ADVERTISEMENT