7. Conditionals It is time to use some Rexx control structures. The first of these will be the conditional. Here is an example: /* Use a conditional to tell whether a number is less than 50 */ pull a if a<50 then say a "is less than 50" else say a "is not less than 50" The program is executed in the manner in which it reads - so, if a is less than 50 then the first instruction is executed, and otherwise the second instruction is executed. The "a<50" is a conditional expression. It is like an ordinary expression (in fact conditional expressions and ordinary numeric expressions are interchangeable), but it contains a comparison operator. There are many comparison operators, as follows: = (equal to) < (less than) > (greater than) <= (less or equal) >= (greater or equal) <> (greater or less) \= (not equal) \> (not greater) \< (not less) All the above operators can compare numbers, deciding whether one is equal to, less than, or greater than the other. They can also compare non-numeric strings, first stripping off leading and trailing blanks. There are analogous comparison operators to these for comparing strings strictly. The main difference between them is that 0 is equal to 0.0 numerically speaking, but the two are different if compared as strings. The other difference is that the strict operators do not strip blanks before comparing. The strict operators are == (equal to) << (less than) >> (greater than) <<= (less or equal) >>= (greater or equal) \== (not equal) \>> (not greater) \<< (not less) Conditional expressions may be combined with the boolean operators: & (and), | (or) and && (xor). They may also be reversed with the \ (not) operator. /* Decide what range a number is in */ pull a if a>0 & a<10 then say "1-9" if a\<10 & a<20 then say "10-19" if \ (a<20 | a>=30) then say "20-29" if a<=0 | a>=30 then say "Out of range" As well as demonstrating the boolean and comparison operators, this program shows that the "else" clause is not required to be present. The above program may also be written using Rexx's other conditional instruction, "select": /* Decide what range a number is in */ pull a select when a>0 & a<10 then say "1-9" when a\<10 & a<20 then say "10-19" when \ (a<20 | a>=30) then say "20-29" otherwise say "Out of range" end The "select" instruction provides a means of selecting precisely one from a list of conditional instructions, with the option of providing a list of instructions to do when none of the above was true. The difference is that if no part of a "select" instruction can be executed then a syntax error results, whereas it is OK to miss out the "else" part of an "if" instruction. Only one instruction may be placed after the "then" or "else" of a conditional instruction, but Rexx provides a way of bracketing instructions together so that they can be treated as a single instruction. To do this, place the instruction "do" before the list of instructions and "end" after it. /* execute some instructions conditionally */ pull a if a=50 then do say "Congratulations!" say "You have typed the correct number." end else say "Wrong!" If you wish for one of the conditional instructions to do "nothing", then you must use the instruction "nop" (for "no operation"). Simply placing no instructions after the "then", "else" or "when" will not work.