Loops in general
- All loops have a loop control variable which is used to determine whether
the loop loops again or stops.
- All loops have 3 parts
- A statement to set the loop control variable to a beginning value. This
initialization must be done before the variable is used.
- A conditional expression comparing the loop control variable to some
condition which will indicate under what conditions the loop will stop.
- Some statement within the logical body of the loop that changes the value
of the loop control variable causing the variable to come closer to the
stopping condition. Once the condition to stop has been reached, the
loop will terminate execution.
- Loops are either logic controlled or counter controlled
- Logic controlled loops are either pre-test (while) or post-test
(do-while, repeat-until, etc.)
- Counter controlled loops (for loops) are usually restricted forms of
a while loop.