HTML and CSS Reference
In-Depth Information
The variable i is initialized to 0 .
The do block is entered. This block of statements will be executed before the while
expression is tested. Even if the while expression proves to be false, this block will
be executed the first time around.
The value of i is displayed in the browser window (see Figure 6.5).
The value of i is incremented by 1.
Now, the while expression is tested to see if it evaluates to true (i.e., is i less than
10 ?). If so, control goes back to line 2 and the block is re-entered.
Figure 6.5 Output from Example 6.6, the do/while loop.
6.3.3 The for Loop
The for loop consists of the for keyword followed by three expressions separated by semico-
lons and enclosed within parentheses. Any or all of the expressions can be omitted, but the
two semicolons cannot. The first expression is used to set the initial value of variables and
is executed just once, the second expression is used to test whether the loop should con-
tinue or stop, and the third expression updates the loop variables; that is, it increments or
decrements a counter, which will usually determine how many times the loop is repeated.
for (initialize; test; increment/decrement)
The preceding format is equivalent to the following while statement:
while( Expression2 )
{ Block; Expression3};
Search WWH ::

Custom Search