Examples of If

Example:

          IF x=+x!(x="") DO BAL
        

In this example, the DO executes if x contains a number or a null string.

Example:

        WRITE !,?50,BAL IF 'BAL WRITE "****"
        IF S EMPTY(acct)=""
        

The IF in the first line changes the value of $TEST, determining the execution of the code following the argumentless IF in the second line. Such argumentless IFs may serve as a form of line continuation.

Example:

        GTM>SET X=1,Y=1,Z=2 KILL UNDEF
        GTM>IF X=1,Y=1,Z=3,UNDEF=0 W "HI"
        GTM>
        

The IF command causes GT.M to cease executing the line after it determines Z is not equal to three (3). Therefore, GT.M never evaluates the reference to the undefined variable and never generates an error.

Example:

        GTM>SET X=1 KILL UNDEF
        GTM>IF X=1!(UNDEF=3) WRITE "HI"
        HI
        GTM>
        

Because GT.M recognizes that the X=1 fulfills the IF, it skips evaluation of the UNDEF variable and executes this IF command without generating an error. Because GT.M does not require such optimizations and in fact discourages them by requiring that all global references maintain the naked indicator, other implementations may generate an error.