Using Logical Expressions

Logical expressions are used in complex conditional instructions and can act as checkpoints to screen unwanted conditions. When you have a series of logical expressions, for clarification, use one or more sets of parentheses to enclose each expression.
IF ((A < B) | (J < D)) & ((M = Q) | (M = D)) THEN …

The following example uses logical operators to make a decision.

Example Using Logical Expressions

/***************************** REXX ********************************/
/* This exec receives arguments for a complex logical expression   */
/* that determines whether a person should go skiing.  The first   */
/* argument is a season and the other two can be 'yes' or 'no'.    */
/*******************************************************************/

 PARSE ARG season snowing broken_leg

 IF ((season = 'winter') | (snowing ='yes')) & (broken_leg ='no')
    THEN SAY 'Go skiing.'
 ELSE
    SAY 'Stay home.'
When arguments passed to this example are "spring yes no", the IF clause translates as follows:
 IF ((season = 'winter') | (snowing ='yes')) & (broken_leg ='no') THEN
      \______________/      \____________/       \_____________/
           false                 true                 true
              \___________________/                    /
                     true                             /
                       \_____________________________/
                                     true
As a result, when you run the exec, you see the message:
    Go skiing.