Decisions, lesson 8
and, or, not
Goal: Combine conditions into one rule.
about 5 min3 practice exercises
Combine conditions with and, or and not.
local coins = 12
local hasKey = false
if coins >= 10 and hasKey then
print("Gate opens")
end
if coins >= 10 or hasKey then
print("One of them is enough here")
end
if not hasKey then
print("Find the key")
end
andis true only when both sides are true.oris true when at least one side is true.notflips true to false and false to true.
With 12 coins and no key, the first if prints nothing, and the other two print their messages.
When you mix them, and is worked out before or. Brackets make your meaning obvious, to Luau and to the next person reading: (isVip or coins >= 10) and not gateBroken.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.