Operations

What if you wanted to do some math in your code? Or check if a certain condition is true? You can use operators!

There are multiple types of operations,

Note for simplicity's sake, some operators will be placed where they're most relevant (ex: logic operators around if-statements)

Math Operations

These are used to do math with data.

Operator
Purpose
Syntax

Addition

Adds two numbers.

a + b

Subtraction

Subtracts two numbers.

a - b

Multiplication

Multiplies two numbers.

a * b

Division

Divides two numbers.

a / b

Modulus

Divides two numbers, but gets the remainder.

a % b

Unary Operations

These are used to modify variables.

Unary Operator
Purpose
Example

+=

Adds n to the variable.

num += 3

-=

Subtracts n from the variable.

num -= 16

*=

Multiplies the variable by n.

num *= 3

/=

Divides the variable by n.

num /= 10

Logic Operators

Logic operators compare values, letting you do logic as the name suggests. For here, you'd use them with if-statements, which we'll cover soon.

Logic Operator
Syntax
Purpose
Example

== (Equals)

value == value

Checks if the two values are equal.

true == true // returns true 1 == 1 // returns true 6 == 9 // returns false

!= (Not equals)

value != value

Returns if the two values are NOT equal.

true != false // returns true 2 != 2 // returns false

&& (And)

condition && condition

Checks if both of the conditions are true.

true && true // returns true

2 == 4 // returns false

|| (Or)

condition || condition

Gives you if one of the conditions is true.

1 == 2 || 3 > 2 // returns true because 3 > 2

! (Not)

!condition

Gives you if the condition is false.

!(2 == 4) // returns true !(3 == 3) // returns false

Last updated