Using Logical Expressions - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

The logical operators are:
Operator
Meaning
&
AND
Returns 1 if both comparisons are true. For example:
(4 > 2) & (a = a)
(2 > 4) & (a = a)
|
Inclusive OR
Returns 1 if at least one comparison is true. For example:
(4 > 2) | (5 = 3)
(2 > 4) | (5 = 3)
&&
Exclusive OR
Returns 1 if only one comparison (but not both) is true. For
example:
(4 > 2) && (5 = 3) /* only one is true, so result is 1 */
(4 > 2) && (5 = 5) /* both are true, so result is 0 */
(2 > 4) && (5 = 3) /* neither one is true, so result is 0 */
Prefix \
Logical NOT
Returns the opposite response. For example:
\ 0
\ (4 > 2)

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:
/* true, so result is 1 */
/* false, so result is 0 */
/* at least one is true, so result is 1 */
/* neither one is true, so result is 0 */
/* opposite of 0, so result is 1 */
/* opposite of true, so result is 0 */
Chapter 3. Using Variables and Expressions
Using Expressions
*/
*/
*/
33

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents