|
The complex loop form is most appropriate when the three expressions work together to control the loop iterations, as in the first example above.
statement1 is executed only once; statement2 is executed after each iteration over the loop body.
If expression initially evaluates to false, the loop body (and statement2) will not be executed even once.
The action of the complex loop statement is almost identical to the following while statement:
statement1
while expression
statements
statement2
However, a continue statement in the while body would not cause statement2 to be executed before the next loop iteration, as it does with the loop statement.
For simple counting loops, the for loop construct is simpler and more efficient.
|