Skip to main content

Assignment Operators

Assignment operators are one of the ways to assign values to variables. If you don't know about variables and assignments yet, you can check them out here.

Here is an example of an assignment operator:

var a = 5
a += 2
print(a) # 7

In this example, a variable is being declared as 5. The next line that has content uses an assignment operator. In the example, it is using the += operator, which adds the value of the right hand side expression to the left hand side (which is the variable). This means that the line does the same thing as a = a + 2.

Here is a table of all the assignment operators in LemonScript:

OperatorExample
a += ba = a + b
a -= ba = a - b
a *= ba = a * b
a /= ba = a / b
a %= ba = a % b
a ^= ba = a ^ b

Assignment operators are made by appending the operation before the equal sign. They simplify a = a + b to a += b, by directly adding b to the value stored in a.