In Lua, you can compare numbers using comparison operators. The following comparison operators are available in Lua:
- >: greater than
- <: less than
- >=: greater than or equal to
- <=: less than or equal to
- ~=: not equal to
- ==: equal to
Here are some examples of how to use comparison operators in Lua with numbers:
-- greater than
if 3 > 2 then
print("3 is greater than 2")
end
-- less than
if 1 < 2 then
print("1 is less than 2")
end
-- greater than or equal to
if 2 >= 2 then
print("2 is greater than or equal to 2")
end
-- less than or equal to
if 4 <= 4 then
print("4 is less than or equal to 4")
end
-- not equal to
if 5 ~= 6 then
print("5 is not equal to 6")
end
-- equal to
if 5 == 5 then
print("5 is equal to 5")
end
In the above examples, the print statements will get executed only if the comparison condition is true.