Operator Precedence
When multiple operations are performed in an expression, each part is computed in a predetermined order called operator precedence. Parentheses can change the order of precedence, forcing a portion of the expression to be treated preferentially. The operations in parentheses are always executed before the outside brackets. However, in parentheses, the operator precedence remains normal.
When an expression has multiple operators, the arithmetic operator is processed first, then the comparison operator is processed, and then the logical operator is processed. All comparison operators have the same precedence, that is, they are processed from left to right in the order in which they appear. Arithmetic and logical operators are processed at the following priority levels:
arithmetic |
Compare |
logical |
Exponential operation (^) |
Equal (=) |
Not |
Negative number (-) |
Unequal (<>) |
and |
Multiplication and division (*, /) |
Less than (<) |
Or |
Divisible (\) |
Greater than (>) |
Xor |
Remainder operation (Mod) |
Less than or equal to (<=) |
Eqv |
Addition and subtraction (+, -) |
Greater than or equal to (>=) |
Imp |
string concatenation (&) |
Is |
& |
When multiplication and division appear in the expression at the same time, each operator is processed in the order that it appears from left to right. Similarly, when addition and subtraction appear in expressions, each operator is also processed in the order that it appears from left to right.
The string concatenation operator (&) is not an arithmetic operator, but for its precedence, it is after all arithmetic operators, and before all comparison operators. The IS operator is a comparison operator of an object reference that does not compare the value of an object or object, and only determines whether two object references refer to the same object.