Order of evaluation
Expressions are evaluated left to right, except for normal rules of precedence and where parantheses
are involved. Parentheses act in the same way as brackets in conventional mathematics, i.e. the
contents of parentheses are evaluated first. This is applied recursively, so that parentheses within
parentheses are evaluated first, then the enclosing parentheses.
(3+4-(2+1)*4) * (3+2)
becomes
(3+4-3*4) * 5
(3+4-12) * 5
-5 * 5
25
Exercises on this section.
Back to expressions.
Back to Contents page.