Loading

Introduction to REXX – Some examples

– A Rexx program should have a comment “/*rexx*/” in the first line
– Rexx statements are Case insensitive
– A rexx program can be executed by giving “EX” to the rexx member containing the rexx program

Hello World program

/************REXX***********/
 SAY "HELLO WORLD"
 EXIT

IF-ELSE in Rexx

/******REXX******/
/* EXECUTE SOME INSTRUCTIONS CONDITIONALLY */
 SAY 'ENTER NUMBER LESS THEN 10 '
 PULL A
 IF A<10 THEN
    DO
       SAY "CORRECT NUMBER!!"
    END
 ELSE SAY "WRONG!"
 EXIT

DO-Loops in Rexx

/*******REXX***********/
  /* SAY "HI" 5 TIMES */
  DO 5
     SAY "HI"
  END
  /**/
  DO C=1 TO 5
     SAY "HI"
  END
  /**/
  DO M=0.3 TO 1.5 BY .3
     SAY "HI"
  END
  /* INFINITE LOOP*/
 /*
 DO FOREVER
     SAY "HI"
 END
 */
 EXIT

DO WHILE and DO UNTIL

DO WHILE runs the loop all the times if the condition given validates to TRUE
DO UNTIL runs the loop all the times if the condition given validates to FALSE

/************REXX***********/
 DO WHILE A = 5
   SAY 'HI'
   /* SOMETHING THAT MODIFIES A */
 END

 DO UNTIL A = 5
   SAY 'HI'
   /* SOMETHING THAT MODIFIES A */
 END
 EXIT

SELECT statement in REXX

The below code shows how to use the SELECT clause. You can also note the use of NOT Operator “\”.

/******REXX******/
/* DECIDE WHAT RANGE A NUMBER IS IN */
 SAY 'ENTER A NUMBER'
 PULL A
 SELECT
    WHEN A>0 & A<100 THEN SAY "1-99"
    WHEN A\<100 & A<500 THEN SAY "100-499"
    WHEN \ (A<500 | A>=1000) THEN SAY "500-29"
    OTHERWISE SAY "OUT OF RANGE"
 END
 EXIT

Dividing one Number by another
PULL gets the value from the user.

/******REXX****************************************************/
 /* DIVIDING ONE NUMBER BY ANOTHER NUMBER */
 /**************************************************************/
 SAY 'DIVIDING ONE NUMBER BY ANOTHER NUMBER'
 SAY 'ENTER NUMERATOR:'
 PULL Z
 SAY 'ENTER DENOMINATOR:'
 PULL N
 IF N=0 THEN
   SAY 'DIVISION BY ZERO'
 ELSE DO
   SAY 'NUM / DENOM IS' Z/N
   SAY 'REST IS' Z//N
 END
 EXIT

A list of REXX functions can be found here.

You can also download a complete Tutorial PDF.

Related Posts




blog comments powered by Disqus

There's 0 Comment So Far

Comments are closed on this post.