The shape of the lesson
By the end of the lesson, learners can
- IF... THEN... ELSE: In the lab, choose the Nested IF program and step through it.
- Nested IF: An IF statement can sit inside the THEN or ELSE branch of another IF.
- CASE OF: When one variable is compared with several single values, a CASE statement is shorter and easier to read than a chain of IFs.
- IF: IF condition, THEN, optional ELSE, ENDIF.
- Boundaries: decide whether the boundary value passes: > or >=.
- Nested IF: test the highest band first; close every IF with its own ENDIF.
- CASE: one variable, single values, first match only, OTHERWISE last.
One picture every idea returns to
Sequence means statements run in order, one after another. Selection means the program chooses which statements to run by testing a condition that is either TRUE or FALSE. An IF statement runs the THEN branch when the condition is TRUE and the optional ELSE branch when it is FALSE. A nested IF is an IF inside another IF. A CASE statement compares one variable with several single values and runs only the first match; OTHERWISE catches every other value.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Choose a path.. Programs make decisions: pass or fail, valid or invalid, which menu option was chosen. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: IF... THEN... ELSE | In the lab, choose the Nested IF program and step through it. Project tab 1 of the lab (Selection with a trace table) and let a student drive it while the class predicts. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Nested IF | An IF statement can sit inside the THEN or ELSE branch of another IF. Model the worked example Dry run on the board, one line at a time. Your turn: What is output when Mark is 40? | Pairs |
| 21 to 30 min | Teach and check: CASE OF | When one variable is compared with several single values, a CASE statement is shorter and easier to read than a chain of IFs. Model the worked example The lab's CASE and REPEAT program on the board, one line at a time. | Mix-Pair-Share |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 18 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in CASE OF, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Mix-Pair-Share
Students mix around the room until you call pair; they pair with the nearest classmate, discuss the prompt, then mix again. Three prompts of rising difficulty, three different partners.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| Check the boundary. | With IF Age > 18 an 18-year-old would be told they are too young. Use >= when the boundary value itself should pass. |
| Test the highest band first. | If the program tested Mark >= 40 first, a mark of 85 would output Pass and never reach Distinction. |
| OTHERWISE must be the last case, and it runs only if none of the cases above it match. | Use an IF, not CASE, when a branch depends on a range such as Mark >= 40. |
Sequence and selection: IF and CASE: worksheet
6 questions, 18 marks. Written in the style of the papers; no past paper question is reproduced.
Describe what is meant by selection and name two types of selection statement.
Write pseudocode that inputs a temperature and outputs "Freezing" if it is below 0, "Cold" if it is from 0 to 15, and "Warm" if it is above 15.
State the output of this pseudocode when X is (a) 12 (b) 5 (c) 20.
IF X > 10
THEN
IF X > 15
THEN
OUTPUT "Large"
ELSE
OUTPUT "Medium"
ENDIF
ELSE
OUTPUT "Small"
ENDIFWrite a CASE statement that inputs a grade (a single character) and outputs "Excellent" for 'A', "Good" for 'B', "Fair" for 'C' and "Not recognised" for anything else.
Explain why a programmer includes an OTHERWISE clause in a CASE statement.
This code should output "Merit" for marks of 60 or more and "Pass" for marks of 40 to 59. Identify the error and correct it.
IF Mark >= 40
THEN
OUTPUT "Pass"
ELSE
IF Mark >= 60
THEN
OUTPUT "Merit"
ENDIF
ENDIFAnswer key and marking notes
- Selection: the program tests a condition and chooses which statements to run depending on whether it is TRUE or FALSE.
- IF statements and CASE statements.
INPUT TempIF Temp < 0 THEN OUTPUT "Freezing"ELSE IF Temp <= 15 THEN OUTPUT "Cold" ELSE OUTPUT "Warm"(nested IF)- Correct ENDIF for each IF and THEN/ELSE structure
- (a) 12 > 10 TRUE, 12 > 15 FALSE: Medium
- (b) 5 > 10 FALSE: Small
- (c) 20 > 10 TRUE, 20 > 15 TRUE: Large
INPUT GradeandCASE OF Grade'A' : OUTPUT "Excellent",'B' : OUTPUT "Good"'C' : OUTPUT "Fair"OTHERWISE OUTPUT "Not recognised"thenENDCASE
- It runs when the value matches none of the listed cases.
- So unexpected or invalid values are still handled, e.g. with an error message.
- The conditions are in the wrong order: any mark of 60 or more is caught by Mark >= 40 and outputs Pass.
- Merit can never be output (the inner IF only runs for marks below 40).
- Correction: test
Mark >= 60first (output Merit), then in the ELSE testMark >= 40(output Pass).
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
In a CASE OF ... ENDCASE statement, when are the statements after OTHERWISE run?
- AOnly when the value matches none of the cases listed above it
- BEvery time, after the matching case has been run
- COnly when the value matches more than one of the cases
- DBefore any of the cases are checked
A program should output "You can vote" for anyone aged 18 or over. Which condition should go in the IF statement?
- A
Age >= 18 - B
Age > 18 - C
Age <= 18 - D
Age = 18
The program is run twice, first with the input 30 and then with the input 15. What is output?
DECLARE Temp : INTEGER
INPUT Temp
IF Temp > 30
THEN
OUTPUT "Hot"
ELSE
IF Temp >= 15
THEN
OUTPUT "Warm"
ELSE
OUTPUT "Cold"
ENDIF
ENDIF- AWarm, then Warm
- BHot, then Warm
- CHot, then Cold
- DWarm, then Cold
A student writes this to grade a mark out of 100. What is output when Mark is 85?
IF Mark >= 40
THEN
OUTPUT "Pass"
ELSE
IF Mark >= 70
THEN
OUTPUT "Distinction"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF- APass
- BDistinction
- CDistinction, then Pass
- DFail
The inputs are R, R, L, X, Q in that order. What is output?
DECLARE Position : INTEGER
DECLARE Move : CHAR
Position ← 20
REPEAT
INPUT Move
CASE OF Move
'L' : Position ← Position - 3
'R' : Position ← Position + 4
OTHERWISE OUTPUT "Beep"
ENDCASE
UNTIL Move = 'Q'
OUTPUT Position- ABeep, Beep, 25
- BBeep, 25
- C25
- DBeep, Beep, 22
This program is meant to output the largest of three different whole numbers A, B and C.
IF A > B
THEN
OUTPUT A
ELSE
IF B > C
THEN
OUTPUT B
ELSE
OUTPUT C
ENDIF
ENDIFWhich set of test data shows that the program is faulty?- AA = 3, B = 1, C = 9
- BA = 1, B = 5, C = 2
- CA = 2, B = 4, C = 7
- DA = 8, B = 3, C = 6
Quiz key
CASE compares the variable with each listed value and runs only the first match; OTHERWISE is the last clause and runs only when no case matched. It is not run after a match, and a value cannot usefully match more than one single value. It is checked last, never first.
Age >= 18 is TRUE for 18 and every age above it. Age > 18 wrongly rejects an 18-year-old. Age <= 18 accepts children and rejects adults over 18. Age = 18 accepts only people who are exactly 18.
30 > 30 is FALSE, so the ELSE branch runs; 30 >= 15 is TRUE, so the first run outputs Warm. For 15, 15 > 30 is FALSE and 15 >= 15 is TRUE, so it also outputs Warm. Hot would need a temperature above 30, and Cold would need one below 15.
85 >= 40 is TRUE, so Pass is output and the ELSE branch (containing the Distinction test) is never reached. This is why the highest band must be tested first. Distinction cannot be output by this program for any mark, because a mark of 70 or more always passes the first test. Only one branch runs, so two outputs are impossible, and Fail needs a mark below 40.
R, R and L give 20 + 4 + 4 - 3 = 25. X matches no case, so Beep is output. Q is also checked by the CASE before the UNTIL test, and it matches no case either, so a second Beep is output; then the loop ends and 25 is output. Beep, 25 forgets that Q goes through the CASE. 25 ignores OTHERWISE. 22 counts the L as -6 or misses one R.
With A = 3, B = 1, C = 9, A > B is TRUE so 3 is output, but 9 is the largest: the program never compares A with C. For 1, 5, 2 it outputs 5; for 2, 4, 7 it outputs 7; for 8, 3, 6 it outputs 8. All three are correct, so they do not reveal the fault.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.