Java Reference
In-Depth Information
WMLScript also provides looping capabilities using the for and while statements. The follow-
ing code counts from 1-100 in WMLScript and updates the contents of a variable as the loop
function increment_variable(strVariableName)
var intCounter;
for (intCounter = 1; intCounter <= 100; intCounter++)
WMLBrowser.setVar(strVariableName, String.toString(intCounter));
Notice that this function demonstrates the use of two of the WMLScript Standard Libraries:
String and WMLBrowser . These libraries will be introduced later in this chapter.
A while loop executes a block of statements until some condition becomes true. Its syntax is
as follows:
while (some_condition)
The break and continue statements are provided to control flow inside a loop. As you might
expect, encountering a break statement causes a loop to immediately exit. A continue state-
ment simply causes a loop to continue by jumping back to the loop beginning.
The Standard Libraries
Although WMLScript is a capable programming language for client-side scripting environ-
ments, it is even more powerful because of the definition and inclusion of six standard libraries
with every validated WAP browser. These libraries are
Lang —This library contains a set of functions that are closely related to the WMLScript
language core. Included in this library are functions for data-type manipulation, absolute
value calculations, and random number generation.
Float —The Float library is optional and is only supported on those clients with float-
ing-point capabilities. Typical functions provided by this library include sqrt() ,
round() , and pow() .
String —The String library contains a set of functions for performing string operations.
Some functions included in this library are length() , charAt() , find() , replace() , and
trim() .
Search WWH ::

Custom Search