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);
}