The solution to most programs of any complexity involves the use of iteration (looping). A loop is used to repeatedly execute a sequence of program statements until, as a result of this repetition; some condition for termination is satisfied.
A properly constructed loop has two main features:
1. The Loop Body, consisting of one or more statements to be executed.
2. A Termination Condition to end the looping process.
There are two general loop structures:
The Condition-Controlled loop exists in two different forms:
- The Entrance-Controlled loop: the body of the loop will only be executed if the entry condition is satisfied. Note that, it is therefore possible that the body of the loop may never be executed if the entry condition is never satisfied.
- The Exit-Controlled loop: looping continues until the exit condition is satisfied. Note that in this type of loop, the body of the loop must be executed at least once.
The Count-Controlled loop: the loop will continue for a fixed number of times.