Previous Topic: Divide by Zero

Next Topic: Parentheses to Control Evaluation Order

Precedence of Operators

In a simple expression there is only one operator so no precedence considerations arise. The calculation is performed according to the operator.

In a compound expression, the evaluation proceeds from left to right with operators being processed according to the standard rules of precedence. So, in a compound expression such as:

(2 + 3 * 4 ** 2)

there are three operators, which are processed in the order:

**

Exponentiation

*

Multiplication

+

Addition

The expression is therefore processed in three steps as follows:

4 ** 2=16
16 * 3=48
48 + 2=50

So an assignment statement coded as:

&A = (2 + 3 * 4 ** 2)

results in &A being assigned a value of 50.