Order of Evaluation

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, the language processor evaluates the expression as follows:
  • First it evaluates expressions within parentheses.
  • Then it evaluates expressions with operators of higher priority before expressions with operators of lower priority.

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

Table 1. Arithmetic Operator Priority
Operator symbol Operator description
- + 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

Reference Reference

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00029.html