HTML and CSS Reference
In-Depth Information
EXPLANATION ( CONTINUED )
6
The default statements are executed if none of the cases are matched.
7
This final break statement is not necessary, but is good practice in case you should
decide to replace the default with an additional case label.
8
The final curly brace ends the switch statement. Figure 6.3 displays examples of
the output.
Figure 6.3 A random number between 1 and 7 determines which case is matched and
executed.
6.3 Loops
Loops are used to execute a segment of code repeatedly until some condition is met.
JavaScript's basic looping constructs are
while
for
do/while
6.3.1 The while Loop
The while statement executes its statement block as long as the expression after the
while evaluates to true; that is, nonnull, nonzero, nonfalse. If the condition never
changes and is true, the loop will iterate forever (infinite loop). If the condition is
false, control goes to the statement right after the closing curly brace of the loop's
statement block.
The break and continue functions are used for loop control.
 
 
 
Search WWH ::




Custom Search