Understand how Lua makes decisions
Understand which lines of code get executed when a decision is made
Conditional statements perform different actions or computations depending on whether a boolean condition is true or false.
A relational operator determines whether a specific relationship exists between two values.
A Boolean expression tests if the conditional statement is true or false.
less than or equal to
greater than or equal to
x < y
x less than y
x <= y
x less than or equal to y
x > y
x greater than y
x >= y
x greater than or equal to y
x == y
x equal to y
x ~= y
x not equal to y
The if conditional statement can be true or false. When the if statement executes, the condition is tested and if true, the code is executed. Otherwise it is skipped.
-- equality examplex = 2if x == 2 thenprint("x is equal to 2")end
-- greater than or equal examplex = 1if x >= 0 thenprint("x is greater than or equal to 0")end
-- not equal examplex = 2if x ~= 1 thenprint("x is not equal to 1")end
-- Common Mistake!if x = 1 thenprint("Why is this a mistake? ")end
The if conditional statement can be true or false. When the if statement executes, the condition is tested and if true, the code is executed. If the condition tested is false, the else code is executed.
io.write("What's your favorite Roblox game? ")game = io.read()if game == "Meep City" thenprint("we love playing Meep City")elseprint("how about Adopt Me?")end
io.write("How much Robux do you have? ")robux = io.read("*number")if robux > 100 thenprint("You have enough to buy a hat")elseprint("Time to earn more Robux!")end