If

Examples of If

The IF command provides conditional execution of the remaining commands on the line. When IF has an argument, it updates $TEST with the truth value of its evaluated argument. GT.M executes the remainder of a line after an IF statement when $TEST is 1 (TRUE). When $TEST is 0 (FALSE), GT.M does not execute the rest of the line.

The format of the IF command is:

        I[F] [tvexpr[,...]]
      
[Note]

Commands with timeouts also maintain $TEST. For information about $TEST, refer to the "Intrinsic Special Variables" chapter in this manual. Because GT.M stacks $TEST only at the execution of an extrinsic or an argumentless DO command, any XECUTE or DO with an argument has the potential side effect of altering $TEST. Therefore, use the argumentless IF with caution.

Example:

        IF A,B ...
        is equivalent to
        IF A IF B
      

An IF with more than one argument behaves as if those arguments were logically "ANDed." However, execution of the line ceases with the evaluation of the first false argument. For IF argument expressions containing the "AND" operator (&), execution still ceases with the evaluation of the first false argument. Any global references within the expression act in sequence to maintain the naked reference.

Postconditionals perform a function similar to IF; however, their scope is limited to a single command or argument, and they do not modify $TEST. For more information on postconditionals, refer to the "General Language Features of M" chapter in this manual.