If-else
Username:  
Password:
  > Home
v User Guide
    > Introduction
    > Hello World
    v Flow Control
       o If-else
       o Switch
       o Foreach loop
       o While loop
       o For loop
    > Function Calls
    > Authentication
    > Database access
    > Content Management
    > Remote Calling
    > Object-Oriented
    > Other Features
> Reference
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> User Guide >> Flow Control >> If-else <=  =>      <  1  >  
If-else

Although BEE handles conditional executions in similar way as other languages do, there are something to note about the specification of the condition.

You can only use values (in the form of {...}) in a condition specification, not variables (not even with "(var)" type cast.)

if ('{sys%time|strftime:%p}' == 'AM') display "Good morning";

else display "Good afternoon";

 

BEE will compare values as string (according to the collating sequence of the character set) unless both strings are purely numeric (integer or real, quoted or not).  If you want to force string comparison on two purely numeric strings, you can append a space.

var a = 10;

var b = 2;

if ({a} > {b}) display "true"; else display "false";  // Output: true

if ('{a}' > '{b}') display "true"; else display "false";  // Output: true

if ('{a} ' > '{b} ') display "true"; else display "false";  // Output: false

 

Although BEE can tolerate a certain degree of ambiguity, quoting values is always a good strategy.  For example:

var a = "OK";

if ({a} == "OK") display "good";

else display "bad";

// Output: good

 

Here the condition appears to BEE as OK == "OK" and the first OK is taken as literal "OK", which the result is "true".  However, the following will result in an error:

var a = "";

if ({a} == "OK") display "good";

else display "bad";

// Output: [Error-Condition-If: == "OK"]

 

The following will work:

var a = "";

if ("{a}" == "OK") display "good";

else display "bad";

// Output: bad

 

As we are speaking about empty string comparison, there is an alternative way to check for null string: the "sizeof" operator in the form of {#...}.

if ('{sys%form:Telephone}' == '')

   display "Please enter your telephone number";

 

The above is equivalent to

if ({#sys%form:Telephone} == 0)

   display "Please enter your telephone number";

 

 

As ice on the cake, BEE handles "elseif", which means, you bet, "else if".

if ('{sys%time|strftime:%p}' == 'AM') display "Good morning";

elseif ('{sys%time|strftime:%p}' == 'PM') display "Good afternoon";

else display "What?";

 

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd