I like this format even better. It becomes more like Duolingo for programming.
One improvement I'd make:
Question
Think for 5–10 seconds
Then immediately reveal the answer and a one-line explanation.
This way you get instant feedback without waiting for me, but you still force your brain to guess first (which is where most learning happens).
Chapter 2 — Decisions (The Brain)
Goal: Make your program take decisions.
You'll learn:
ifelseifelse==,~=,<,>,<=,>=and,or,not
Q1
A game should give a reward only if the player reaches level 10.
Which keyword starts the decision?
A) for
B) while
C) if
D) print
✅ Answer: C
💡 if means "If this condition is true, do something."
Q2
age = 20
if age >= 18 then
print("Adult")
end
What gets printed?
A) Adult
B) Nothing
C) Error
D) 18
✅ Answer: A
💡 20 >= 18 is true, so "Adult" is printed.
Q3
Which operator means equal to?
A) =
B) ==
C) !=
D) =>
✅ Answer: B
💡 = stores a value. == compares two values.
Q4
coins = 100
if coins == 50 then
print("Rich")
end
What happens?
A) Rich
B) Nothing
C) Error
D) 50
✅ Answer: B
💡 100 == 50 is false, so the code inside if is skipped.
Q5
Which operator means NOT equal in Lua?
A) !=
B) <>
C) ~=
D) =!
✅ Answer: C
💡 Lua uses ~= instead of !=.
Q6
score = 80
if score ~= 50 then
print("Different")
end
Output?
A) Different
B) 50
C) Nothing
D) Error
✅ Answer: A
💡 80 is not equal to 50.
Q7
Which operator means greater than?
A) <
B) >
C) >=
D) ==
✅ Answer: B
💡 > checks whether the left value is larger.
Q8
health = 5
if health < 10 then
print("Low Health")
end
Output?
A) Low Health
B) Nothing
C) Error
D) 10
✅ Answer: A
💡 5 < 10 is true.
Q9
If the first if is false, which keyword checks another condition?
A) elseif
B) repeat
C) while
D) return
✅ Answer: A
💡 elseif lets you test another condition.
Q10
marks = 70
if marks >= 90 then
print("A")
elseif marks >= 60 then
print("B")
else
print("C")
end
Output?
A) A
B) B
C) C
D) Nothing
✅ Answer: B
💡 First condition is false. Second is true.
Q11
Which keyword runs when none of the conditions are true?
A) default
B) end
C) else
D) continue
✅ Answer: C
💡 else is the "everything else" option.
Q12
coins = 5
if coins > 10 then
print("Rich")
else
print("Poor")
end
Output?
A) Rich
B) Poor
C) Error
D) Nothing
✅ Answer: B
💡 5 > 10 is false, so else runs.
Q13
and means...
A) Either condition can be true.
B) Both conditions must be true.
C) Opposite.
D) Skip the condition.
✅ Answer: B
💡 and = both.
Example:
age >= 18 and hasID == true
Both must be true.
Q14
age = 20
hasTicket = true
if age >= 18 and hasTicket then
print("Enter")
end
Output?
A) Enter
B) Nothing
C) Error
D) false
✅ Answer: A
💡 Both conditions are true.
Q15
or means...
A) Both conditions.
B) Only first condition.
C) At least one condition.
D) Opposite.
✅ Answer: C
💡 Only one condition needs to be true.
Q16
day = "Sunday"
if day == "Saturday" or day == "Sunday" then
print("Weekend")
end
Output?
A) Weekend
B) Sunday
C) Nothing
D) Error
✅ Answer: A
💡 One side of or is true.
Q17
not true becomes...
A) true
B) false
C) nil
D) 1
✅ Answer: B
💡 not flips a boolean.
Q18
loggedIn = false
if not loggedIn then
print("Please Login")
end
Output?
A) Logged In
B) Please Login
C) false
D) Error
✅ Answer: B
💡 not false becomes true.
Q19
Which symbol ends an if block?
A) }
B) stop
C) end
D) finish
✅ Answer: C
💡 Lua closes blocks with end.
Q20 (Most Important)
What is the purpose of an if statement?
A) Store values
B) Repeat code
C) Make decisions
D) Print text
✅ Answer: C
💡 If variables are the memory of a program, then if is its brain—it lets the program choose what to do based on conditions.
🧠 Pareto Summary (Remember only these)
=→ Store a value.==→ Compare values.~=→ Not equal.<,>,<=,>=→ Compare numbers.if→ Make a decision.elseif→ Try another condition.else→ Everything else.and→ Both must be true.or→ At least one must be true.not→ Flip true ↔ false.Every
ifends withend.
I think we can make this course even more engaging. Starting from Chapter 3, I suggest each chapter have 25–30 MCQs arranged from easiest to hardest, with real-life scenarios, tiny code snippets, prediction questions ("What will this print?"), and a 5-question boss battle at the end that mixes everything from the chapter. That gives you much stronger retention than isolated questions.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.