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.


Previous Page Page 29 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page