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.
|