GENERATE/PREV.gifGENERATE/NEXT.gif

If Expression

The syntax for an <if_expr> is one of:

if <expr> then <expr> [ else <expr> ]

if <expr> do <expr>

The first <expr> is a test expression that must evaluate to true or false, such as a comparison or logical expression. If the result is true, the then or do <expr> is evaluated and its value is returned as the result of the whole <if_expr>. If the result is false, either the optional else <expr> is evaluated and returned as the result of the <if_expr>, or if there is no else or the do form is used, the <if_expr> returns the value undefined.

Examples:

if a > b do (print d; print e)

a = if d == 0 then 0 else a / d

The do form is provided particularly for use during interactive sessions in the MAXScript Listener. When you enter expressions for immediate evaluation into the Listener, MAXScript determines if your expression is complete and then evaluates it. If you use the optional else form as a top-level command in the Listener and you want to omit the else <expr>, as in the following example, MAXScript continues to "wait and see" if you are going to enter an else, because the line break after the then <expr> is legal and does not cause MAXScript to evaluate the current line right away:

if match x y then print x

When you use the optional else form inside a block or other expression, MAXScript can determine from the code that follows it whether you omitted the optional else. Use the do form for if statements without an else as top-level commands in the Listener:

if match x y do print x