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?";
|