These operators should be consistent across every language.
+
operator
Example:
x
result = 2 + 2
result += 1 # most languages have this too
# If your language doesn't, it'd look like this:
result = result + 1
-
operator
Example:
xxxxxxxxxx
result = 3 - 2
result -= 1 # most languages have this too
# If your language doesn't, it'd look like this:
result = result - 1
*
operator
Example:
xxxxxxxxxx
result = 3 * 2
result *= 4 # most languages have this too
# If your language doesn't, it'd look like this:
result = result * 4
/
operator
Example:
xxxxxxxxxx
result = 4 / 2
result /= 2 # most languages have this too
# If your language doesn't, it'd look like this:
result = result / 2
%
operator
Example:
xxxxxxxxxx
--[[
Modulo, or modulus, is a special operator. It returns the **remainder** of dividing two numbers. For example, when you divide 4 by 2, you have nothing left over, so `4 % 2` will return 0. But when you divide 3 by 2, two goes into 3 once, leaving 1 left over. Therefore, `3 % 2` will return 1
]]
local result = 3 % 2
print(result) -- will print "1"
One of modulo's main uses, is to check if something is a factor of something else. For example, if number x
is evenly divisible by number y
(dividing them results in a remainder of 0), then y
is a factor of x
. Therefore, to check if y
is a factor of x
, you'd simply have to check if (x % y == 0)
.