
Possible Solution (Internal Subroutine named CHECK)
check:
/*******************************************************************/
/* This internal subroutine checks for valid input of "HEADS",
*/
/* "TAILS", or "QUIT". If the user entered anything else, the
*/
/* subroutine tells the user that it is an invalid response and
*/
/* asks the user to try again. The subroutine keeps repeating
*/
/* until the user enters valid input. Information is returned to */
/* the main exec through commonly used variables.
*/
/*******************************************************************/
DO UNTIL outcome = 'correct'
SELECT
WHEN response = 'HEADS' THEN
outcome = 'correct'
WHEN response = 'TAILS' THEN
outcome = 'correct'
WHEN response = 'QUIT' THEN
EXIT
OTHERWISE
outcome = 'incorrect'
SAY "That's not a valid response. Try again!"
SAY "Heads, tails, or quit?"
PULL response
END
END
RETURN
Possible Solution (External Subroutine named THROW)
/****************************** REXX *******************************/
/* This external subroutine receives the valid input from the user,*/
/* analyzes it, gets a random "throw" from the computer and
*/
/* compares the two values. If they are the same, the user wins. */
/* If they are different, the computer wins. The outcome is then */
/* returned to the calling exec.
*/
/*******************************************************************/
ARG input
IFinput = 'HEADS' THEN
userthrow = 0
/* heads = 0 */
ELSE
userthrow = 1
/* tails = 1 */
compthrow = RANDOM(0,1)
/* choose a random number between */
/* 0 and 1 */
IFcompthrow = userthrow THEN
outcome = 'human'
/* user chose correctly
*/
ELSE
outcome = 'machine'
/* user didn't choose correctly
*/
RETURN outcome
Writing a Function
A function is a series of instructions that an exec invokes to perform a specific task
and return a value. As was described in “Chapter 5. Using Functions” on page 61, a
function may be built-in or user-written. An exec invokes a user-written function the
same way it invokes a built-in function — by the function name immediately
Writing a Subroutine;
Chapter 6. Writing Subroutines and Functions
77
Summary of Contents for TSO/E REXX
Page 1: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Page 2: ......
Page 3: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Page 10: ...viii z OS V1R1 0 TSO E REXX User s Guide ...
Page 12: ...x z OS V1R1 0 TSO E REXX User s Guide ...
Page 14: ...xii z OS V1R1 0 TSO E REXX User s Guide ...
Page 18: ...xvi z OS V1R1 0 TSO E REXX User s Guide ...
Page 20: ...2 z OS V1R1 0 TSO E REXX User s Guide ...
Page 58: ...Tracing Expressions with the TRACE Instruction 40 z OS V1R1 0 TSO E REXX User s Guide ...
Page 78: ...60 z OS V1R1 0 TSO E REXX User s Guide ...
Page 86: ...Built In Functions 68 z OS V1R1 0 TSO E REXX User s Guide ...
Page 128: ...Issuing Other Types of Commands from an Exec 110 z OS V1R1 0 TSO E REXX User s Guide ...
Page 136: ...Debugging Execs 118 z OS V1R1 0 TSO E REXX User s Guide ...
Page 170: ...Protecting Elements in the Data Stack 152 z OS V1R1 0 TSO E REXX User s Guide ...
Page 201: ...Part 3 Appendixes Copyright IBM Corp 1988 2001 183 ...
Page 202: ...184 z OS V1R1 0 TSO E REXX User s Guide ...
Page 222: ...Using Variables 204 z OS V1R1 0 TSO E REXX User s Guide ...
Page 226: ...208 z OS V1R1 0 TSO E REXX User s Guide ...
Page 238: ...220 z OS V1R1 0 TSO E REXX User s Guide ...
Page 241: ......