![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
The defect of many while
loops is that the details that govern the
looping appear in three places: the place where the counting variable is
initialized, the place where it is tested, and the place where it is
reassigned. Such distribution makes the looping difficult to understand.
Accordingly, you also need to know about the for
statement:
for (entry expression; Boolean expression; continuation expression) embedded statement
The entry expression is evaluated only once, when the for
statement
is entered. Once the entry expression is evaluated, the Boolean expression
is evaluated, and if the result is not 0
, the embedded statement is
evaluated, followed by the continuation expression. Then, the
Boolean-expressionembedded-statementcontinuation-expression evaluation
cycle continues until the Boolean expression eventually evaluates to
0
.