WMLScript Developer's Guide

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 6 - Statements
Section 34 out of 57 total sections , Section 8 out of 11 sections in this chapter


For Statements

A for statement creates a loop that executes as long as a stated condition is true. The for statement consists of three optional expressions enclosed in parentheses and separated by semicolons followed by the code the for statement executes.

Typically, the first expression (var index = 0 in the example below) is used to initialize a counter variable. This expression can declare a new variable with the var keyword. The scope of the declared variable is the remainder of the function.

The second expression can be any WMLScript expression that evaluates to a Boolean or an invalid value. This condition is evaluated on each pass through the loop. If the condition is true, the statement is executed. This conditional test is optional. If omitted, the condition always evaluates to true and the statements in the for loop are always executed.

The third expression is generally used to update or increment the counter variable. This statement is executed as long as the condition is true.

The following is an example of a for statement:

for (var index = 0; index < 100; index++) {  
    count += index;  
    myFunc(count);  
}  

[Cover] [Previous Section] [Next Section] [Index]


Part Number DKDS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.