// Math operators: +, -, *, /, %, ** (power operator)
let mathResult = 100 + 3 ** 2
// Logical operators: &&, ||
let conditionA = 10 > 1
let conditionB = 1 != 3
if (conditionA && conditionB) {
print('all ok')
}
// Comparison operators: >, <, >=, <=, ==, !=
if (1 != 10) {
print('all ok')
}
// Bitwise operators: & (and), | (or), ^ (xor), << (shift to left), >> (shift to right)
// This evaluates to 5:
let bitwiseResult = 1 & 2 | 4
// Unary operators: - (negation), ! (logical negation), ~ (bitwise not), # (length operator)
let notResult = ~4
let length = #[1, 2, 3]
// Compound assignment statements (works with all operators)
let compound = 100
compound *= 10
compound += 5
// Increment and decrement statements
let incremented = 1
incremented++
// Ternary operator
let ternaryResult = 2 > 1 ? 'two is more than one' : 'something is wrong'
|
-- Math operators: +, -, *, /, %, ** (power operator)
local mathResult = 100 + 3 ^ 2
-- Logical operators: &&, ||
local conditionA = 10 > 1
local conditionB = 1 ~= 3
if (conditionA and conditionB) then
print('all ok')
end
-- Comparison operators: >, <, >=, <=, ==, !=
if (1 ~= 10) then
print('all ok')
end
-- Bitwise operators: & (and), | (or), ^ (xor), << (shift to left), >> (shift to right)
-- This evaluates to 5:
local bitwiseResult = bit32.bor(bit32.band(1, 2), 4)
-- Unary operators: - (negation), ! (logical negation), ~ (bitwise not), # (length operator)
local notResult = bit32.bnot(4)
local length = #{1, 2, 3}
-- Compound assignment statements (works with all operators)
local compound = 100
compound = compound * 10
compound = compound + 5
-- Increment and decrement statements
local incremented = 1
incremented = incremented + 1
-- Ternary operator
local ternaryResult = (2 > 1) and ('two is more than one') or ('something is wrong')
|