Lesson 4: Making Choices — IF ... THEN ... ELSE Conditionals
Learning objective
Students will evaluate true/false conditions and trace algorithms that use IF ... THEN and IF ... THEN ... ELSE branches to adapt to changing obstacles or treasures on a grid.
Materials
- 5×5 tabletop grids and robot tokens
- Dealt warm-up symbol cards (showing shapes
▲/● and numbers 1–6), coins or two-sided mystery tokens where Heads = STAR ★ and Tails = EMPTY (no star), and Rock X tokens
Vocabulary
- Condition: A statement that can be checked right now and is either TRUE or FALSE (for example, "Square ahead has a Rock").
- Conditional (
IF ... THEN ... ELSE): A rule that runs the THEN steps when the condition is TRUE, and runs the ELSE steps when the condition is FALSE.
Lesson flow
1. Warm-up: Card Check Conditionals (8 min)
- Deal each student or pair a fictional symbol card (for example, a card showing either a Triangle
▲ or Circle ● and a number from 1 to 6), so no student needs to disclose personal attributes. Students may perform the output action, hold up a response card, or point to a choice on their desk:
- Rule 1 (
IF ... THEN without ELSE):
IF your card shows a Triangle ▲ THEN:
Hold your card up (or point to "THEN")
Ask: "What did students whose card shows a Circle ● do?" (Nothing—because there was no ELSE branch!).
- Rule 2 (
IF ... THEN ... ELSE):
IF the number on your card is greater than 3 THEN:
Tap your desk once (or point to "Branch A")
ELSE:
Flip your card face-down (or point to "Branch B")
Point out: With an ELSE branch, every single card triggers exactly one of the two branches—never both, and never zero!
- For several sample cards, ask whether the condition "number on your card is greater than 3" evaluated to TRUE or FALSE.
2. Direct instruction: Smart Robots that Check Before Stepping (12 min)
Explain: In Lessons 2 and 3, we knew ahead of time where every Rock X was located. What if a rock falls onto the path after we write our program? A robot equipped with a downward sensor (to check current square has a STAR ★) and a front sensor (to check square ahead is CLEAR or square ahead has a ROCK X) can use a conditional inside a loop!
Write this program on the board and trace it together along Row 1 (A1 to E1), starting at A1 facing East, with a surprise Star ★ on B1 and D1:
REPEAT 4 TIMES:
FORWARD 1
IF current square has a STAR ★ THEN:
PICK UP
Trace all 4 iterations together in a table on the board:
| Iteration |
After FORWARD 1, robot is on... |
Is current square has a STAR ★ TRUE or FALSE? |
Does PICK UP run? |
| 1 |
B1 ★ |
TRUE |
Yes (PICK UP #1) |
| 2 |
C1 |
FALSE |
No |
| 3 |
D1 ★ |
TRUE |
Yes (PICK UP #2) |
| 4 |
E1 |
FALSE |
No |
Now show an IF ... THEN ... ELSE sidestep rule when the square ahead on Row 1–3 might be blocked (in these classroom puzzles, the adjacent lane to the left/North is known to be in bounds and clear; note that a real robot in an unknown environment would also need to check that side square before moving):
IF square ahead is CLEAR THEN:
FORWARD 1
ELSE:
TURN LEFT
FORWARD 1
3. Guided practice: Mystery Token Corridor (15 min)
- Each pair sets up Row 3 of their 5×5 grid (
A3, B3, C3, D3, E3) with the Robot starting on A3 facing East.
- On squares
B3, C3, and D3, the "Environment Partner" flips a coin to place either a Star (★, Heads) or nothing (Empty, Tails), and places at most one Rock (X) on E3.
- The "Programmer Partner" traces this single smart algorithm across all three layouts without rewriting the code:
REPEAT 3 TIMES:
FORWARD 1
IF current square has a STAR ★ THEN:
PICK UP
IF square ahead has a ROCK X THEN:
TURN LEFT
FORWARD 1
ELSE:
FORWARD 1
- Partners record for all three coin-flip setups (Setup 1, Setup 2, and Setup 3):
- How many stars were picked up?
- Which square (
E3 or D4) did the robot finish on?
4. Wrap-up & Exit check (10 min)
A robot starts on A2 facing East. Square B2 is EMPTY, and square C2 has a ROCK X. The robot runs:
Step 1:
IF square ahead has a ROCK X THEN:
TURN LEFT
ELSE:
FORWARD 1
Step 2:
IF square ahead has a ROCK X THEN:
TURN LEFT
FORWARD 1
ELSE:
FORWARD 1
Answer these three questions:
- In Step 1, the robot is at
A2 looking at B2. Is the condition square ahead has a ROCK X TRUE or FALSE? Which square does the robot end Step 1 on?
- In Step 2, the robot is on
B2 facing East and looking at C2 (which has a Rock X). Is the condition TRUE or FALSE? Which branch (THEN or ELSE) runs?
- What square is the robot standing on after Step 2 finishes (
B3, C2, or B1)?
Worked answers for exit check
- FALSE (because
B2 is empty). The ELSE branch runs (FORWARD 1), so the robot ends Step 1 on B2 facing East.
- TRUE (because
C2 has a Rock X). The THEN branch runs (TURN LEFT, then FORWARD 1).
B3 (from B2 facing East, TURN LEFT faces North, and FORWARD 1 steps onto B3).