Previous Next Chapter

Calc.rexx

This program introduces the DO instruction, which repeats the execution of program statements. It also illustrates the exponentiation operator ( ** ). Enter this program and save it as REXX:Calc.rexx. To run the program, use the " RX calc " command.

Program 3. Calc.rexx

/*Calculate some squares and cubes.*/
DO i = 1 to 10 /*Begin loop - 10 iterations*/
SAY i i**2 i**3 /*Perform calculations*/
END /*End of loop*/
SAY `All done.'

The DO instruction repeatedly executes the statements between the DO and END instructions. The variable " i " is the index variable for the loop and is incremented by 1 for each iteration (repetition). The number following the symbol TO is the limit for the DO instruction and could have been a variable or a full expression rather than just the constant 10.

Generally, ARexx programs use single spacing between alphanumeric characters. In Program 3, however, spacing is closed up between the exponentiation characters ( ** ) and the variables ( i , and 2, i and 3).

The statements within the loop have been indented. This is not required by the language, but it makes the program more readable, because you can easily visualize where the loop starts and stops.

Top Previous Next Chapter