Welcome to Developer's Home Wednesday, April 23, 2014
Home - DevelopersHome.com

WMLScript Conditional Statements


Preferences - Do not show ads

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;


Page 26 of 71 Previous Page | Next Page
Contents at a Glance
Print this Web Page | | Back to Top
Custom Search

Feedback Form (Expand)

What do you think about this web page?






WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page