Page 94 - Code & Click - 5
P. 94
ITERATION OR LOOP
A Loop is a set of instructions which repeats itself continuously until a particular
condition is satisfied. A loop is used when a process needs to be repeated a certain
number of times or until a certain condition is achieved.
Example 5: Draw a flowchart to accept a number and multiply it by itself 10 times.
Start
Read N
Count = 1
Product = 1
Product = Product × N
Product = Product × N Count = Count + 1
Count = Count + 1 Is
Count > 10? No
Is
Count > 10? No
The part of the flowchart given above
Yes represents the loop in the flowchart.
Print Product
Stop
The instructions Product = Product × N and Count = Count + 1 are repeated until the
value of Count is less than or equal to 10. When it becomes greater than 10, the loop
ends.
When a loop is used in a flowchart, a value called Counter is used to keep track of the
number of times the loop is to run. The value Count in the above example is a counter
which checks how many times the loop has run.
Example 6: Draw a flowchart to calculate the average marks of each of the 40 students
in a class and display the names of the students who got more than 80% marks.
The average of marks of a studentd is calculated by adding the marks in all the subjects
and dividing it by the number of subjects. This process will be repeated for each student
till the number of students is less than or equal to 40. If the average marks are above
80, the name of the student is displayed.
92