Iteration (Repetition)

There are three types of program construct:
  • sequence;
  • selection;
  • iteration (repetition).
A sequence is simply a group of statements executed in the order they appear in the source program. We have seen that if statements and case statements perform selection. Iteration can be achieved by a:
  • for loop;
  • repeat loop;
  • while loop.
Each type of loop has its own characteristics:
  • A for loop is used when the number of iterations is known in advance.
  • A repeat loop carries on repeating until some condition is satisfied, so must run at least once.
  • A while loop tests a condition at the start of a loop and only continues while the condition is true. If the condition is false at the outset then the rest of the code in the loop will not be executed at all.

Now, we consider each of these in turn:

Programming - a skill for life!

Pascal Programming Tutorials