WMLScript
Conditional Statements
Conditional
statements enable your script to make decisions. With conditional
statements, you can specify different actions to be done when
different conditions occur.
if
Statement
WMLScript's
if statement uses the following syntax. The part inside
brackets [] is optional. The syntax is the same as that of C++, Java
and JavaScript. You should be very familiar with the syntax if you
have some programming experience with these languages.
if
(condition) { WMLScript
statement(s) } [else { WMLScript statement(s) }]
If
condition is the Boolean value true, the statement(s) enclosed
in the first curly brackets {} will be executed; if condition
is false or invalid, the statement(s) enclosed in the second curly
brackets {} will be executed. The following WMLScript example
demonstrates how to use the if
statement:
... var
wmlscript_tutorial_partnum; if (page_title=="WMLScript
Tutorial Part 1") { wmlscript_tutorial_partnum =
1; } else { wmlscript_tutorial_partnum = 2; }
If
the value of the page_title variable is equal to the string
"WMLScript Tutorial Part 1", the script
"wmlscript_tutorial_partnum = 1;" will be executed.
Otherwise the script "wmlscript_tutorial_partnum = 2;" will
be executed.
In
the above WMLScript example, there is only one statement enclosed
within the curly brackets. In this case, the curly brackets can be
omitted, which means the WMLScript example can be written like this:
... var
wmlscript_tutorial_partnum; if (page_title=="WMLScript
Tutorial Part 1") wmlscript_tutorial_partnum =
1; else wmlscript_tutorial_partnum = 2;
|
Feedback Form (ExpandCollapse)
|
|