/* REXX */
/* Arrays are built by appending a period and an index to a variable name */
/* Typically the size of the array is stored in index 0 */
/* Build a list of 50 prime numbers */
list.0= 0
z= 3
DO WHILE list.0<50
IF \ HAS_DIVIDERS(z) THEN DO /* IF NOT ... THEN */
list.0= list.0+1
ind= list.0
list.ind= z
END
z= z+2
END
DO i=1 TO list.0
SAY list.i
END
EXIT
/* Below is a function. The word PROCEDURE was added, to give it a */
/* local variable pool. Exchange of data with the calling program is */
/* done through argument passing and result return mechanism. */
HAS_DIVIDERS: PROCEDURE
/* Pick up first (and only) argument */
z= ARG(1)
result= 0
DO i=2 TO z-1
IF (z//i)=0 THEN DO
/* leave loop if i is a divider of z */
result= 1
LEAVE i
END
END
RETURN result