Previous Next Chapter

Age.rexx

This program displays a prompt for input and then reads entered information.

Program 2. Age.rexx

/*Calculate age in days*/
SAY `Please enter your age:'
PULL age
SAY `You are about' age*365 `days old.'

Save this program as REXX:Age.rexx and run it with the command:

RX age

This program begins with a comment line that describes what the program will do. All ARexx programs begin with a comment. The SAY instruction displays a request for input on the console.

The PULL instruction reads a line of input from the user, which in this case is the user's age. PULL takes the input, converts it to uppercase letters, and stores it in a variable. Variables are symbols which may be assigned a value. Choose descriptive variable names. This example uses the variable name "age" to hold the entered number.

The final line multiplies the variable "age" by 365 and issues the SAY instruction to display the result. The "age" variable did not have to be declared as a number because its value was checked when it was used in the expression. This is an example of typeless data. To see what would happen if age was not a number, try running the program again with a non-numeric entry for the age. The resulting error message shows the line number and type of error that occurred.

Top Previous Next Chapter