OPERATOR:  conditional:  ? : ;

  ? : ;  
The conditional operator is used to assign one of two possible values to an expression based upon the results from a boolean test applied to a specified operand.
The conditional operator is used in the following format:
expression = operand1 ? operand2 : operand3;
This operator behaves as follows:
  • A boolean (true or false) test is performed on operand1.
  • If the test proves true, the expression is assigned the value of operand2.
  • If the test proves false or invalid, the expression is assigned the value of operand3.
Code for ConditionalExample.wml
<?xml version="1.0"?>

<card id="card1">
   conditional example
   <do type="accept">
      <go href="ConditionalExample.wmls#findconditional()" />

<card id="card2">
   expression = $(express)


Code for ConditionalExample.wmls
extern function findconditional()
   var oper1;
   var oper2 = "second operand";
   var oper3 = "third operand";
   var boo = Dialogs.prompt("true, false, or invalid", "");
   if(boo == "true") oper1 = true;
   if(boo == "false") oper1 = false;
   if(boo == "invalid") oper1 = invalid;
   var exp = oper1 ? oper2 : oper3;
   WMLBrowser.setVar("express", exp);

Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information