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[,...]]
Because IF is a conditional command, it does not support a command postconditional.
The scope of the IF is the remainder of the line.
The action of IF is controlled by the value of the expression and by $TEST, if there is no expression.
IF with no argument acts on the existing value of $TEST (which it does not change); in this case, at least two (2) spaces must follow the IF to separate it from the next command on the line.
An indirection operator, and an expression atom evaluating to a list of one or more IF arguments form a legal argument to IF.
![]() |
|
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.