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")
endNote:
- Conditions don’t require parentheses.
- The
endkeyword is required to close eachifblock.
Truthiness:
Only false and nil are treated as false. Everything else is true, including 0 and "".
