Lua's Relational Operators

Relational

Lua's relational operators are more or less the same as in most other languages:

local x = 2
local y = 3

print(x > y) -- false
print(x < y) -- true

print(x >= y) -- false
print(x <= y) -- true

print(x <= x) -- true
print(x >= x) -- true

The relational operators allow one to determine when values are greater-than or less-than others, and include a variant that also allows the variables to be equal.

Equality

Lua's equality operator uses two equal signs ==, which is differentiated from the variable assignment operator = which uses a single equal sign:

local x = 2
local y = 3

print(x == y) -- false
print(x == x) -- true

This operator returns true when the two values are equal, otherwise it returns false.

Inequality

Like equality, it can often be useful to know when two values are not equal. Lua implements this using the ~= operator:

local x = 2
local y = 3

print(x ~= y) -- true
print(x ~= x) -- false

This operator returns false when the two values are equal, otherwise it returns true.