When a for loop executes, the following occurs:
1. The initializing expression initialExpression, if any, is executed. This expression usually initializes one or more loop counters, but the syntax allows an expression of any degree of complexity. This expression can also declare variables.
2. The condition expression is evaluated. If the value of condition is false, the for loop terminates .If the value of condition is true, the loop statements execute. If the condition expression is omitted entirely, the condition is assumed to be true.
3. The statement executes. To execute multiple statements, use a block statement ({ ... }) to group those statements.
4. The update expression increment Expression, if there is one, executes, and control returns to step 2.
|