Examples of Else

Example:

        IF x=+x SET x=x+y
        ELSE WRITE !,x
        

The IF command evaluates the conditional expression x=+x and sets $TEST. If $TEST=1 (TRUE), GT.M executes the commands following the IF. The ELSE on the following line specifies an alternative action to take if the expression is false.

Example:

        IF x=+x DO ^GOFISH
        ELSE SET x=x_"^"_y
        

The DO with an argument after the IF raises the possibility that the routine ^GOFISH changes the value of $TEST, thus making it possible to execute both the commands following the IF and the commands following the ELSE.

Example:

          OPEN dev::0 ELSE WRITE !,"Device unavailable" QUIT
        

This ELSE depends on the result of the timeout on the OPEN command. If the OPEN succeeds, it sets $TEST to one (1) and GT.M skips the rest of the line after the ELSE. If the OPEN fails, it sets $TEST to zero (0), and GT.M executes the remainder of the line after the ELSE.