The
while statement creates a loop that evaluates a expression to
see if it is true or false, and if true, executes
a block of statements and then repeats the loop, or if false,
immediately exits the loop.
The while
statement will iterate the loop as long as the specified expression
remains true. Therefore, if the expression never tests
false, the loop will continue forever in what is called an
"infinite loop."
The block of statements
executed by the while statement can be any legal WMLS code
(including more while statements).
<?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>
while
example
</p>
<do type="accept">
<go
href="WhileExample.wmls#findwhile()" />
</do>
</card>
<card id="card2">
<p>
sum = $(sum)
</p>
</card>
</wml>Code for WhileExample.wml
extern function findwhile()
{
var sum = 0;
while(sum < 1000)
{
sum = sum +
Lang.random(100);
}
WMLBrowser.setVar("sum", sum);
WMLBrowser.go("WhileExample.wml#card2");
};
Code for WhileExample.wmls