-
Notifications
You must be signed in to change notification settings - Fork 0
Operators
Serra Royale edited this page Jun 11, 2025
·
3 revisions
Operators are used to cause an operation (or mathematical action) to be performed on one (such as !) or two operands. The easy and common example is 1 + 2 where 1 and 2 are operands, and the + is the operator. This concept can be extended much further with LSL since operands can be variables with the special case of the assignment operators requiring that the left hand side be a variable.
The following table lists the operators in descending order of evaluation, i.e. higher in the table means higher evaluation precedence. Multiple operators on the same line share evaluation precedence. Parenthesize an expression if you need to force an evaluation order.
| Operator | Description | Usage Example |
|---|---|---|
()
|
parentheses: grouping and evaluation precedence |
integer val = a * (b + c);
|
[]
|
brackets: list constructor |
list lst = [a, 2, "this", 0.01];
|
(type)
|
typecasting |
string message = "The result is:" + (string)result;
|
! ~ ++ --
|
logical NOT, bitwise NOT, increment, decrement |
counter++;
|
* / %
|
multiply/dot product, divide, modulus/cross product |
integer rollover = (count + 1) % 5;
|
-
|
subtraction, negation |
integer one = 3 - 2;
integer neg_one = -1;
|
+
|
addition, string concatenation |
integer two = 1 + 1;
string text = "Hello" + " world";
|
+
|
list concatenation |
list myList = [1, 2, 3] + [4, 5];
list newList = oldList + addList;
|
<< >>
|
left shift, right shift |
integer eight = 4 << 1;
integer neg_one = -2 >> 1;
|
< <= > >=
|
less than, less than or equal to, greater than, greater than or equal to |
integer isFalse = (6 <= 4);
|
== !=
|
comparison: equal, not equal |
integer isFalse = ("this" == "that");
|
&
|
bitwise AND |
integer zero = 4 & 2;
integer four = 4 & 4;
|
^
|
bitwise XOR |
integer zero = 4 ^ 4;
integer six = 4 ^ 2;
|
|
|
bitwise OR |
integer four = 4 | 4;
integer six = 4 | 2;
|
&& ||
|
logical AND, logical OR |
integer isFalse = (FALSE && TRUE);
integer isTrue = (FALSE || TRUE);
|
= += -= *= /= %=
|
assignment |
integer four = 4;
integer eight = four; eight *= 2;
|