Examples of Looping
Suppose you wish to visit the botanical garden, and therefore, arelooking for one of your friends to accompany you. So you take out your
book of few phones and select a likely prospect. Dial the number, make
few talk, and finally invite the friend to visit. If he (or she) accepts the
offer, you have finished your work. If you are refused, then go back and
select another number. These actions are shown in a flow chart in Figure
The essential concept in this algorithm is the branch back to an
earlier statement to create a loop. A loop is a sequence of instructions
which is repeated several times. Note that each time the programme goes
through the loop a different telephone number is used; the instructions
remain unchanged but the data operated on differs. If you eventually get
an acceptance, you would reach the end block. However, if you keep on
getting rejections, then you re-execute the loop instructions. Since you
only have a finite number of telephone numbers in your book, you must
stop when the data run out.
No comments:
Post a Comment