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 |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data