The solution to most programs of any complexity involves the use of loops. 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:
- The Loop Body, consisting of one or more statements to be executed.
- A Termination Condition to end the looping process.
There are two general loop structures:
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.
Next: While Loop