home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 January / CHIPCD1_98.iso / software / tipsy / zoc / install.fil / SCRIPT / RXSAMPLE / TUTORIAL / 7_ARRAY.ZRX < prev    next >
Text File  |  1996-08-26  |  982b  |  46 lines

  1. /* REXX */
  2.  
  3. /* Arrays are built by appending a period and an index to a variable name */
  4. /* Typically the size of the array is stored in index 0                   */
  5.  
  6. /* Build a list of 50 prime numbers */
  7.  
  8. list.0= 0
  9. z= 3
  10.  
  11. DO WHILE list.0<50 
  12.     IF \ HAS_DIVIDERS(z) THEN DO  /* IF NOT ... THEN */
  13.         list.0= list.0+1
  14.         ind= list.0
  15.         list.ind= z
  16.     END
  17.  
  18.     z= z+2
  19. END
  20.  
  21. DO i=1 TO list.0
  22.     SAY list.i
  23. END
  24.  
  25. EXIT
  26.  
  27.  
  28. /* Below is a function.  The word PROCEDURE was added, to give it a     */
  29. /* local variable pool.  Exchange of data with the calling program is   */
  30. /* done through argument passing and result return mechanism.           */
  31. HAS_DIVIDERS: PROCEDURE 
  32.     /* Pick up first (and only) argument */
  33.     z= ARG(1)
  34.     result= 0
  35.  
  36.     DO i=2 TO z-1
  37.         IF (z//i)=0 THEN DO
  38.             /* leave loop if i is a divider of z */
  39.             result= 1
  40.             LEAVE i
  41.         END 
  42.     END
  43.  
  44.     RETURN result
  45.  
  46.