If/Else Statements
Control flow in Lua starts with the if
statement. You can use if
, elseif
, and else
for conditional branching:
score = 85
if score >= 90 then
print("Excellent")
elseif score >= 75 then
print("Good")
else
print("Keep improving")
end
Note:
- Conditions don’t require parentheses.
- The
end
keyword is required to close eachif
block.
Truthiness:
Only false
and nil
are treated as false. Everything else is true, including 0
and ""
.