break Statement: Quitting a Loop

Preferences - Do not show ads

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.


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.


Page 29 of 71 Previous Page | Next Page
Contents at a Glance
Print this Web Page | | Back to Top

Feedback Form (Expand)

What do you think about this web page?






WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page