Looping (Flowchart Part 3)

Filed under , on Monday, January 25, 2010

1

Looping refers to using one or more steps repeatedly.
Loops are of two types:
•    Fixed
•    Variable
Consider the following examples to understand the two different types of looping:
Example 4
To calculate the sum of monthly expenditure for an entire year, the flowchart is as follows in Figure 6. Figure 6 illustrated a fixed loop because the total number of months in a year is 12. Thus, this loop cannot be executed for more than 12 times.
We consider the expenditure of one month at a time and add it to the total expenditure. After the expenditure of each month is added to the total expenditure, we examine whether the number of months is equal to 12.

Figure 6


If ‘Yes’ then there are no more months left and we display the total expenditure and stop. If ‘No, we accept the expenditure of the next month.
Since the number of the months in a year is fixed, this loop cannot be executed more than 12 times. Hence, this is an example of a fixed loop.
Example 5    
Another example, a survey is carried out in a town. Information such as the name, sex, age etc. of each person is available. To maintain a list of people aged 50 and above in the town we draw a flowchart as follows:
Figure 7

Figure 7 illustrates a variable loop as we do not know the exact number of people in the town. This loop continues till the name and age of the last person in the town is read.
Given below is the basic flowchart for a loop.
Figure 8

Loops are fixed if operations are repeated a fixed number of times. The values being computed or handled inside the loop have no effect on the number of times the looping operation is done.
Variable loops are the ones where the operations are repeated until a specified condition is met. The number of times that the loop is repeated may vary.

Comments Posted (1)

Flowcharts are always better to represent the programming basics. Flowcharts are there to show the flow of a process. Drawing process from a flowchart software could make processes easier to explain, just like the looping structure given here.

Post a Comment