Phase 1: Prepare
Step 1 Warm-up recall
From M3.L2: evaluate NOT (5 > 3).
Private: nothing you type here is sent or stored.
Step 2 Learning goal
By the end of this lesson you can:
- describe if, else if and else (Foundation);
- trace a chain for a given input (Core);
- explain why the order of conditions matters (Core).
Phase 2: Teach
Step 3 A familiar example
A ticket office charges by age. The clerk does not check every rule for every person; she goes down the list and stops at the first rule that fits.
Step 4 Clear explanation
A decision structure chooses between steps. In an if, else if, else chain, the conditions are checked from top to bottom, the steps of the first true condition are run, and all later conditions are skipped. The final else runs only if no condition was true. Here is an invented price rule: under 5 is free; under 18 costs £4; under 65 costs £8; otherwise the price is £5.
| Age | Which condition is true first? | Price (£, invented) |
|---|---|---|
| 3 | age < 5 | 0 |
| 17 | age < 18 | 4 |
| 18 | age < 65 | 8 |
| 65 | none, so otherwise | 5 |
Because a person aged 3 meets the first condition, the later conditions never run. A person aged 18 fails age < 5 and age < 18 and meets age < 65, so pays £8. A person aged 65 meets none of the three, so the otherwise branch gives £5. The order matters: if age < 65 were checked first, a three-year-old would pay £8. Exactly one branch runs, which makes chains easy to trace by hand, as in Module 1. For a language that writes these chains, see the entry on the programming language.
Step 5 Worked example (4 marks)
Trace the price rule for age 17.
- age < 5? 17 < 5 is false. (1 mark)
- age < 18? 17 < 18 is true. (1 mark)
- Run this branch: price £4, and skip the rest. (1 mark)
- Answer: £4. (1 mark)
Phase 3: Practise
Step 6 Learner practice (instant-marked)
1. In an if, else if, else chain, how many branches run?
Only the first true branch runs.
2. The else part runs when:
It is the fallback.
3. Using the invented price rule, age 18 pays:
It fails the first two conditions and meets age < 65.
4. Conditions in a chain are checked in what order?
The order is part of the rule.
Phase 4: Close
Step 7 Recap
- The first true condition decides; the rest are skipped.
- Else runs only if nothing earlier was true.
- The order of conditions changes the result.
Step 8 Exit ticket (ungraded)
Trace the price rule for ages 4, 64 and 65.
Private: nothing you type here is sent or stored.
Step 9 Go further (Extension)
Rewrite the chain with the senior rule first and explain which ages would be wrong.
Common mistakes
| Mistake | Why it fails |
|---|---|
| Running several branches | Only the first true branch runs. |
| Putting a general condition first | Put the narrowest conditions first. |
| Leaving out the otherwise branch | Say what happens when nothing matches. |
Limits. Prices and ages here are invented for teaching; real policies must be taken from the organisation concerned.