if / elseif / else
Try it yourself →Executes code based on a condition.
Syntax
if condition then ... elseif ... else ... end
Description
Written with then and end. Not equal is written with ~= (not !=). Keywords and/or/not are used.
Example
local score = 75
if score >= 50 then
print("Passed")
else
print("Failed")
endExpected output
Passed
When to use?
Flow branching.
Common mistakes
- ⚠️ Not equal is ~=, NOT !=. Blocks are closed with end.