WMLScript » Statements » if else

Syntax:
if else

The if else statement evaluates a specified expression contained in the if statement to determine if it is true or false. If true, the block of statements associated with the if statement is executed. If false, the block of statements associated with the else statement is executed. Note that you cannot provide a test expression for the else statement.

The block of statements executed by the if or else statement can be any legal WMLS code (including more if and if else statements).

Examples

Code:
<?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>
   if else example
   </p>
   <do type="accept">
      <go href="IfElseExample.wmls#findifelse()" />
   </do>
</card>

<card id="card2">
<p>
   rand is $(str)
</p>
</card>

</wml>
Explanation:

Code for IfElseExample.wml

Language(s): WML
Code:
extern function findifelse()
{
   var str;
   var rand = Lang.random(10000);
   if(rand < 5000)
   {
      str = "less than 5000";
   }
   else
   {
      str = "NOT less than 5000";
   }
   WMLBrowser.setVar("str", str);
   WMLBrowser.go("IfElseExample.wml#card2");
};
Explanation:

Code for IfElseExample.wmls

Language(s): WML

See Also: