Conditionals

if statements

The if statement supports both simple and complex logical operations.   if, else, and else if branches are supported with and without open and close braces ('{' and '}').  Unlike many programming languages, a semicolon is required at the end of the final close brace (if used).

Form 1:

if (<expression>)
    <expression>;
else if (<expression2>)
    
<expression>;
else
    
<expression>;

Form 2:

if (<expression>)
{
    <expression1>;
    
<expression2>;
};

? : operator

The ? operation can be used to define a simple if operation, and when combined with a : can include an else clause.  The true and false branches each allow a single expression.

Form:

<expression> ? <true expression> [: <false expression>]

If no : or <false expression> is included, the original expression is returned.  For example:

0 ? 100, yields 0
1 ? 100
, yields 100
(1==1) ? 100 : 200, yields 100
(1==0) ? 100 : 200, yields 1000

Note: Users must pay attention to operator precedence.   The statement "1==1 ? 100 : 200" yields 0 since it is interpreted as "1==(1 ? 100 : 200)", and 1 == 100 is false or 0.

switch statement

The switch statement resembles the C/C++ switch statement with the following exceptions:

  1. The closing brace must include a semicolon

  2. Users cannot consolidate expressions under multiple case statements.  The following is not supported:

    case 0x01:
    case 0x02:
        <expression>;
        break ;

  3. Case statements are not checked for uniqueness.

Form:

switch (<expression>)
{
case <expression1>:
    
<expression1a>;
    <expression1b>;
    break;

case <expression2>:
    <expression2a>;
    <expression2b>;
    break;

case <expression3>:
    <expression3a>;
    <expression3b>;
    break;

default:
    <expression4a>;
    <expression4b>;
    break;

};

Loops

While and for loops resemble the C/C++ constructs, but with the following exceptions:

  1. "break" and "continue" statements are not supported

  2. The ending brace (if used) must include a trailing semicolon

  3. Loops and expression aborted on error

while loop

Form 1:

while <expression1>
    <expression2>;

Form 2:

while <expression1>
{
    <expression2>;
    <expression3>;
};

for loop

Form 1:

for (<init expression>; <control expression>; <post expression>)
    <expression>;

Form 2:

for (<init expression>; <control expression>; <post expression>)
{
    <expression1>;
    <expression2>;
};

More Information