| [[Basic_lua:_Operators#elseif|elseif]] || Used to add additional if queries, if the initial query condition was not met.
| [[Basic_lua:_Operators#elseif|elseif]] || Used to add additional if queries, if the initial query condition was not met.
|-
|-
| [[Basic_lua:_Operators#end|end]] || This is used to close various queries or functions; there must be the same amount of '''end''' as '''if'''; except in instances where '''elseif''' has been used.
| <span class="vsyellow">end</span>]] || This is used to close various queries or functions; there must be the same amount of '''end''' as '''if'''; except in instances where '''elseif''' has been used.
|}
|}
Revision as of 16:02, 2 September 2022
Lua operators are expressions used to perform calculations or to pass arguments between different value types.
local a = 1
local b = 2
local result = a + b
print( result )
click to enlarge
subtract
3 - 2 = 1
local a = 3
local b = 2
local result = a - b
print( result )
click to enlarge
inverse
inv of 3 = -3
local a = 3
local result = -a
print( "original value: " .. a, "inversed value: " .. result )
click to enlarge
multiply
2 x 2 = 4
local a = 2
local result = a * a
print( result )
click to enlarge
divide
10 ÷ 5 = 2
local a = 10
local b = 5
local result = a / b
print( result )
click to enlarge
power
base of 2, power of 8 (2ⁿ) = 256
local a, b = 2, 16
local result = a ^ b -- generate answer
-- break down power function into string result (ignore this code)
function power(i1, i2)
local val = "" -- clear string
--+--
for i = 1, i2 do -- generate the longhand math formula
if i < i2 then val = val..i1.."*" else val = val..i1 end
end
return "which is the equivalent of " .. val
end
print("power value of "..a.." & "..b.." = " .. result, power(a,b))
click to enlarge
remainder
remainder of 25 ÷ 4 = 1
local a = 25
local b = 4
local result = a / 4
local remainder = a % b
local decimal = remainder / b
print("result: 25 ÷ 4 = " .. result, "remainder: .25 x 4 = " .. remainder, "decimal: 1 ÷ 4 = " .. decimal )