Also note here that any one, two, or all of the three expressions can be
omitted in a for loop but the two semicolons (;) must be placed separating the expressions. Also,
expr1 and expr2 can be lists of expressions separated by a comma. Thus, expr1 or expr2 may
become compound statements also.
Remember the following points regarding for loops:
1. A for loop can also be written equivalently using
while
or
do-while loops
as follows:
For loop implementation using while loop:
expr1;
while (boolExpr) {
statements;
expr2
}
Similarly, a for loop may be implemented by using a do-while loop also:
expr1;
do {
statements;
expr2
}
while (boolExpr);
2. Any valid value can be initialized to expr1 that will act as the counter.
3.
Do'stlaringiz bilan baham: |