Condition-controlled and count-controlled loops – OCR A Level Computer Science lesson (H446)
Students learn to write count-controlled and condition-controlled loops in Python and pseudocode, and state when WHILE and DO … UNTIL test their conditions.
Lesson 4 of 16 in unit 12.2 Programming Foundations and Computational Thinking, taught in Year 12, Autumn 1. It answers one big question: How do you choose the right loop and make it stop?
By the end, students can write count-controlled and condition-controlled loops in Python and pseudocode, and state when WHILE and DO … UNTIL test their conditions.
- The Build (the main task)
- Write a program that totals the bikes returned to each of Fernbridge CycleShare's 12 city-centre stations in an hour, using a count-controlled loop, and validates each entry with a condition-controlled loop so that only 0 to 40 is accepted (6 marks).
- Support version
- A Parsons problem: the lines of a correct Python solution jumbled, with two distractor lines (range(1, 12) and a WHILE that tests the wrong way).
- Challenge
- Rewrite the validation as DO … UNTIL in OCR pseudocode and explain why it suits validation better than WHILE.
- Real-world link
- Fernbridge CycleShare's control room counts returns at city-centre stations to plan where to move bikes.
- Key words
- Condition-controlled loop, Count-controlled loop and Terminate, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “for i = 1 to 12 in OCR pseudocode and for i in range(1, 12) in Python both run 12 times”; “WHILE and DO … UNTIL are the same loop with different words”.
- OCR H446 specification
- 2.2.1 (a).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Students need computers for the main task.
Also sold in the Programming Foundations and Computational Thinking unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
An independent resource written for OCR A Level Computer Science (H446). It is not endorsed by OCR or Cambridge University Press & Assessment. Programming project (NEA) lessons teach general skills on a made-up example project and give supervised time, within JCQ's rules on the help a centre may give.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for A Level Computer Science
See allStudents learn to name the debugging tools in their IDE and write a short algorithm in both Python and OCR exam pseudocode.
Free sample lessonStudents learn to identify sequence, selection and iteration in code, and choose between IF, ELSEIF and SWITCH for a task.
Students learn to choose the correct primitive data type for each item of data and use casting to convert between types.
Written for the specifications named. Not endorsed by or affiliated with any exam board.