13.3. break Statement:
Quitting a Loop
The
break statement is used to quit a loop. It must be put inside
while loops or for loops. The following WMLScript
example demonstrates how to use the break statement:
var
result = 0; for (var counter=0; counter<10;
counter++) { break; result += 2; }
After
the execution the above WMLScript code, the value of result is
0. This is because the break statement exits the for
loop. The statement "result += 2;" is never executed.
13.4. continue Statement:
Quitting Current Iteration of a Loop
The
continue statement is used to quit the current iteration of a
loop in WMLScript. The next iteration will be started if the loop's
conditional expression evaluates to true. The continue
statement must be put inside while loops or for loops.
The following script demonstrates how to use the continue
statement:
var
result1 = 0; var result2 = 0; for (var counter=0; counter<10;
counter++) { result1 += 2; continue; result2 +=
2; }
After
the execution of the above WMLScript code, the value of result1
is 20 and that of result2 is 0. This is because when the
WMLScript interpreter encounters the continue statement, it
will end the current iteration. Hence, the statement "result2 +=
2;" is never executed.
Feedback Form (ExpandCollapse)
|
|