EasyManua.ls Logo

IBM TSO/E REXX

IBM TSO/E REXX
242 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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
IF input = 'HEADS' THEN
userthrow = 0 /* heads = 0 */
ELSE
userthrow = 1 /* tails = 1 */
compthrow = RANDOM(0,1) /* choose a random number between */
/*0and1*/
IF compthrow = 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

Table of Contents

Related product manuals