Skip to main content

Choosing the Right Loop

Now that we have looked at the three types of loop which are available in Pascal (For, Repeat ... Until and While ... Do), let's take a closer look at a programming example.

Suppose we want to read in a sequence of exam marks, one after the other, and calculate their average. There are three situations, which might arise:

  1. The number of marks to be read in is known by the programmer when the program is written.
  1. The number of marks to be read in is not known when the program is written but is known when the program is executed.
  1. The number of marks to be read in is not known during writing or execution.

Next: Situation 1