Operator order of precedence

You determine the value of an expression by the order in which the parts are evaluated. Operators with greater precedence are evaluated before operators with less precedence. Operators with the same precedence are evaluated from left to right.

To override the normal order of evaluation in an expression, use parentheses. Subexpressions in parentheses are evaluated before the other parts of the expression, from left to right.

The following table summarizes the order of operator precedence. The operands in the table are binary except where noted. Operators on the same line have the same precedence. In order of highest-to-lowest, the precedence of LotusScript® operators is:

Type of Operator

Operator

Operation

Arithmetic

^

Exponentiation

-

Unary negation (unary minus)

*, /

Multiplication, floating-point division

\

Integer division

Mod

Modulo division (remainder)

-, +

Subtraction, addition

Concatenation

&

String concatenation

Relational (Comparison)

=, <>, ><, <, <=, =<, >, >=, =>, Like

Numeric and string comparison Equal to, not equal to, not equal to, less than, less than or equal to, less than or equal to, greater than, greater than or equal to, greater than or equal to, Contains (substring matching)

Object reference comparison (Same precedence as Relational)

Is, IsA

Tests object type, refers to the same object

Logical

Not

Logical negation or one's complement

And

Boolean or bitwise And

Or

Boolean or bitwise Or

Xor

Boolean or bitwise exclusive Or

Eqv

Boolean or bitwise logical equivalence

Imp

Boolean or bitwise logical implication

Assignment

=

Assignment

Examples

This example shows the order of precedence for Arithmetic operators.

Print 6 + 4 / 2                    ' Prints 8
Print (6 + 4) / 2                  ' Prints 5
Print -2 ^ 2                       ' Prints -4
Print (-2) ^ 2                     ' Prints 4

This example shows the order of precedence for Comparison operators:

Print 5 < 3                        ' Prints False
Print 5 > 3                        ' Prints True
Print "Alphabet" = "Alpha" & "bet" ' Prints True
Print 4 And 10 - 2 * 3 / 2
' Output: 4 because 2 * 3 = 6
'         6 / 2 = 3
'         10 - 3 = 7 (binary 111)
'         4 (binary 100) And 7 (binary 111) = 4 (binary 100).

You can alter the default order in which operations are performed by enclosing the expressions you want evaluated first in parentheses.

For example:

anInt% = 5
anotherInt% = 10
aThirdInt% = 7
print anInt% - (anotherInt% + aThirdInt%)
' Output: -12

or, alternatively:

theResult% = -1 Or -1 Imp 0
Print theResult%
' Output: False
' because -1 Or -1 = True, and True Imp 0 is False. 
theResult% = -1 Or (-1 Imp 0)
Print theResult%
' Output: True
' because -1 Imp 0 is False, and -1 Or False is True.

A function is evaluated before any of the operators in an expression.

For example:

Print -1 > 0
' Output: False
Print Abs(-1) > 0
' Output: True