z/OS TSO/E REXX User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Order of Evaluation

z/OS TSO/E REXX User's Guide
SA32-0982-00

When you have more than one operator in an arithmetic expression, the order of numbers and operators can be critical. For example, in the following expression, which operation does the language processor perform first?
7 + 2 * (9 / 3) - 1
Proceeding from left to right, it is evaluated as follows:
  • Expressions within parentheses are evaluated first.
  • Expressions with operators of higher priority are evaluated before expressions with operators of lower priority.

Arithmetic operator priority is as follows, with the highest first:

Arithmetic Operator Priority

- +
Prefix operators
**
Power® (exponential)
* / % //
Multiplication and division
+ -
Addition and subtraction
Thus the preceding example would be evaluated in the following order:
  1. Expression in parentheses
    7 + 2 * (9 / 3) - 1
             \___/
               3
  2. Multiplication
    7 + 2 * 3 - 1
        \___/
          6
  3. Addition and subtraction from left to right
    7 + 6 - 1 = 12

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014