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

  1. /* REXX */
  2.  
  3. /* This program lets the user enter a value.  It is done in a sub-    */
  4. /* routine with global variable space that modifies the variables     */
  5. /* of the calling program part.  Then another subroutine checks  if   */
  6. /* the value can be divided by any other number.                      */
  7.  
  8. CALL ENTERIT
  9.  
  10. IF HAS_DIVIDERS(number)=0 THEN DO 
  11.     SAY number||" is a prime number!"
  12. END
  13. ELSE DO 
  14.     SAY number||" is not a prime number!"
  15. END
  16.  
  17. EXIT
  18.  
  19. /* Below is a subroutine.  It has access to the varibale pool of the  */
  20. /* calling program.  Of course, this could be done in a more elegant  */
  21. /* way.                                                               */
  22. ENTERIT:
  23.     SAY "Please enter a number (up to 1000)"
  24.     PULL number
  25.     RETURN
  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.