Exercises - Using The Select/When/Otherwise/End Instruction - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

Using Conditional Instructions
Each SELECT must end with an END. Indenting each WHEN makes an exec
easier to read.
Exercises - Using the SELECT/WHEN/OTHERWISE/END
Instruction
"Thirty days hath September, April, June, and November; all the rest have
thirty-one, save February alone ..."
Write an exec that provides the number of days in a month. First have the exec ask
the user for a month specified as a number from 1 to 12 (with January being 1,
February 2, and so forth). Then have the exec reply with the number of days. For
month "2", the reply can be "28 or 29".
ANSWER
46
z/OS V1R1.0 TSO/E REXX User's Guide
Example Using SELECT/WHEN/OTHERWISE/END
/******************************** REXX *****************************/
/* This exec receives input with a person's age and sex. In
/* reply it displays a person's status as follows:
/*
BABIES
- under 5
/*
GIRLS
- female 5 to 12
/*
BOYS
- male 5 to 12
/*
TEENAGERS - 13 through 19
/*
WOMEN
- female 20 and up
/*
MEN
- male 20 and up
/*******************************************************************/
PARSE ARG age sex .
SELECT
WHEN age < 5 THEN
status = 'BABY'
WHEN age < 13 THEN
DO
IF sex = 'M' THEN
status = 'BOY'
ELSE
status = 'GIRL'
END
WHEN age < 20 THEN
status = 'TEENAGER'
OTHERWISE
IF sex = 'M' THEN
status = 'MAN'
ELSE
status = 'WOMAN'
END
SAY 'This person should be counted as a' status '.'
/* person younger than 5
/* person between 5 and 12
/* boy between 5 and 12
/* girl between 5 and 12
/* person between 13 and 19
/* man 20 or older
/* woman 20 or older
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents