Representing Algorithm With Flowchart & Pseudocode
Representing Algorithm With Flowchart & Pseudocode
Algorithm with
Flowchart &
Pseudocode
Algorithms
FOR count =
1 to 5
Print count
WHILE CONSTRUCT
In the WHILE construct a set of statements/instructions are repeated
for as long as the condition is true. This WHILE construct should be
used when the number of times the instructions are to be repeated
are unknown.
In the WHILE construct, the condition is tested if it is true, the
instructions are repeated until the condition becomes false.
Instructions before the WHILE construct are carried out once. The
WHILE loops is repeated until the condition becomes false which
forces the loop to stop.
If, after carrying out the instructions befpre the loop, the condition is
tested and is false, the instructions is skipped and the computer then
continues with the statements after the ENDWHILE.
The terminating causes the loop to stop.
Syntax:
WHILE <condition> DO
<action to be taken if condition is true>
WHILE loop Examples
WHILE (noOfItems <= 5) DO
BEGIN
Read price
noOfItems = noOfItems + 1
Total =Total + price
END
END WHILE
Or
cars = 0 counter variable is initialized to zero
WHILE cars <=10 DO
BEGIN
PRINT “ENTER model of car: “
INPUT model
cars = cars + 1
PRINT “Model # “, cars, “is “, model
END
ENDWHILE
NOTE: in the WHILE construct loop MUST be initialized before the counter variable
is incremented (increased).
WHILE loop
Flowchart
Problem 1: Read
in three marks and
display their
average.
Flowchart for
Selection Structure
Problem:
Ask the user to
enter two
numbers then
display the
greater number.
Activity