4.8 Operator precedence

When Xpressionist calculates a statement, it follows a certain order in which the operations are executed. A multiplication will always be calculated before an addition, for example. The hierarchy is as follows:


( )

! and ++ and --

* and / and % and ^

+ and -

< and <= and > and >=

== and !=

&&

||

= and += and -= and *= and /=


// gets calculated before

// gets calculated before

// gets calculated before

// gets calculated before

// gets calculated before

// gets calculated before

// gets calculated before

// gets calculated before

Operators in the same row in the above table have equal precedence; if a statement contains two or more operators from the same row, then the operator furthest to the left gets read and calculated first.

Parenthesis can be used to group a set of conditions or elements of a statement. As shown in the example below, these are useful for controlling and altering the order of operator calculation.

Examples:

Cube.XScale = 4 + 5 * 2;

This assigns Cube.XScale the value 14.

Cube.XScale = ( 4 + 5 ) * 2;

This assigns Cube.XScale the value 18.

Cube.XScale = 4 + 5 - 2;

This assigns Cube.ScaleX the value 7. The + is the first to execute because it's further to the left than the - in the statement.

Xpressionist 3.5