break statement
continue statement
if statement
while statement
STATEMENT: for
for
The
for
statement repeatedly executes the same block of statements as long as a stated test condition, based upon a counting mechanism, remains
true
.
A counting variable is created that allows the
for
loop to execute (iterate) a specified number of times. As long as the test condition remains
true
, for each iteration of the counter, the block of statements is executed. The first time that the test condition returns
false
, the
for
loop is terminated, the block of statements is not executed, and the program jumps to the first line of code (if any) after the
for
loop.
The test condition is defined using three optional expressions.
The first expression sets the starting value for a counting variable. You can use the
var
statement to create the counting variable inside this expression.
The second expression defines the ending value for the counting variable. For each iteration, a boolean
true
or
false
test is performed on the expression. As long as
true
is returned, the
for
loop continues to iterate. When
false
is returned, the
for
loop is immediately terminated.
The third expression is used to increment or decrement the counting variable.
Note that the
for
loop does not have to finish all of the prescribed iterations. For example, you can leave a
for
loop by executing a
break
statement or calling the
Lang.exit
function.
The block of statements executed by the
for
loop can be any legal WMLS code (including more
for
statements).
Code for ForExample.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
for example
</p>
<do type="accept">
<go href="ForExample.wmls#findfor()" />
</do>
</card>
<card id="card2">
<p>
for loop is over
</p>
</card>
</wml>
Code for ForExample.wmls
extern function findfor()
{
var end = 95;
for
(var count=0; count < end; count++;)
{
// You can place any code you desire here
}
WMLBrowser.go("ForExample.wml#card2");
};
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information