Lesson 3 of 5 · MRT Station
Conditions: a 45-minute coding lesson
A free 45-minute lesson on conditions (if / else) for ages 7–12. Students teach a robot to wait for MRT fare gates and train doors.
- 45 minutes
- Pairs, whole class
- One device per pair, plus a projector
Learning objectives
By the end of the lesson, students can:
- Explain that a condition lets a program choose what to do.
- Use if / else to react to something that changes, like a gate opening.
- Combine a condition with a "repeat until" loop.
Key words
- Condition:
- A question with a yes or no answer, like "are the doors open?".
- If / else:
- If the answer is yes, do one thing; otherwise, do another.
- Repeat until:
- Keep repeating until something is finished.
You'll need
- One laptop, Chromebook or iPad per pair, open to dotcodecampus.com/maze/mrt/1. No accounts or installs.
- A projector or screen for the demo.
- Optional: the printable unplugged grid game for the warm-up, and certificates to finish.
Lesson flow
Minutes 0–8
Unplugged warm-up
- Play "Traffic Light": students walk on the spot when you hold up green and freeze on red.
- Write the rule on the board: if the light is green, walk; else, wait.
- Ask: could you have known the colours in advance? Why is a rule better than a fixed plan?
Minutes 8–15
Demo on the projector
- Open MRT Station level 1 (dotcodecampus.com/maze/mrt/1) and watch the doors open and shut before running anything.
- Solve it by counting "wait" blocks, then open level 3 and show how an if / else inside "repeat until finished" works no matter the timing.
- Show the Python: "while not finished():" and "if door_open():".
Minutes 15–35
Paired play: levels 1–6
- Pairs work through levels 1–6, swapping roles at each level.
- The gate and door chips under the board show whether they are open. Ask pairs to watch them while the robot runs.
- Level 6 needs one if inside another. Ask: what two questions must both be true before the robot moves?
- If a pair is stuck, use the Step button to go through the program one block at a time.
Minutes 35–42
Class discussion
- Why is "if the gate is shut, wait" better than counting waits?
- What would happen at a real MRT station if the doors had no sensors?
- Where do you see if / else around you? (Automatic doors, lift buttons, a game checking if you pressed jump.)
Minutes 42–45
Exit ticket
- Finish the rule: "If it is raining, ___; else, ___." Then write a robot version for the train doors.
Early finishers: Write if / else rules for a school canteen queue robot: what should it check before moving forward?
Answer key
One three-star solution per level, in Python. Other solutions with the same number of blocks earn three stars too. Jump links take the class straight to a level.
Level 1: Mind the Doors
7 blocksdotcodecampus.com/maze/mrt/1
move_right() move_right() wait() wait() wait() wait() move_right()
Level 2: Long Platform
2 blocksdotcodecampus.com/maze/mrt/2
while not finished():
move_right()Level 3: Doors Open?
4 blocksdotcodecampus.com/maze/mrt/3
while not finished():
if door_open():
move_right()
else:
wait()Level 4: Fare Gates
4 blocksdotcodecampus.com/maze/mrt/4
while not finished():
if gate_closed():
wait()
else:
move_right()Level 5: Down to the Platform
6 blocksdotcodecampus.com/maze/mrt/5
move_down()
move_down()
while not finished():
if door_open():
move_right()
else:
wait()Level 6: Rush Hour
6 blocksdotcodecampus.com/maze/mrt/6
while not finished():
if gate_closed():
wait()
else:
if door_open():
move_right()
else:
wait()Bonus: Last Train Home
8 blocksdotcodecampus.com/maze/mrt/bonus
move_down()
move_down()
while not finished():
if gate_closed():
wait()
else:
if door_open():
move_right()
else:
wait()