if statementsΒΆ

Use if to implement a conditional statement.


(if conditional_expression

If conditional_expression evaluates to be true (non zero), the subsequent code (up to the else) is executed. If an else clause is present, the code after the else will be excuted if conditional_expression evaluates to zero.

Examples of using the if statement:

(if (HaveMouse)         ; HaveMouse is a procedure call
        (DrawStatus "Mouse is available!")
        (DrawStatus "Mouse is NOT available!")

(if (or SomeVar (and SomeOtherVar (not AnotherVar)) )
        ; do something

Note that the if condition is not enclosed in parentheses unless it is itself an expression. If it’s just a plain value, then it looks like:

       (if someVariable
               (Prints "someVariable is TRUE")

Ternary operator

If statements can also be evaluated (like the ternary operator (?:) in c++).


       ; Set myVar to 5 if we've opened the sewer. Otherwise set it to 10.
       (= myVar
               (if (Btest FLAG_OpenedSewer) 5 else 10)

See also: switch statement, switchto statement, cond statements.