Condition-controlled loops (WHILE, DO UNTIL) – OCR GCSE Computer Science lesson (J277)
Pupils learn to write WHILE loops that stop when a condition changes, trace DO UNTIL loops in OCR Exam Reference Language, and spot infinite loops.
Lesson 5 of 11 in unit 10.3 Binary, Boolean Logic and Iteration, taught in Year 10, Spring 1. It answers one big question: How can a program keep repeating until something changes?
By the end, pupils can write WHILE loops that stop when a condition changes, trace DO UNTIL loops in OCR Exam Reference Language, and spot infinite loops.
- The Build (the main task)
- Write a Python program for the smart door lock that uses a WHILE loop (a condition-controlled loop) to keep asking for the PIN until 4721 is entered, printing 'Wrong PIN' after each wrong try, then prints 'Door unlocked'.
- Support version
- Parsons problem: jumbled lines with an if distractor that only asks twice.
- Challenge
- Lock out after three wrong PINs, using a counter and a combined condition.
- Real-world link
- The smart door lock keeps asking for the PIN until the right one is entered.
- Key words
- Condition-controlled loop, Infinite loop and Predict, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “A WHILE loop always runs at least once, even if its condition starts False”; “An infinite loop is a syntax error that the computer will spot”.
- OCR J277 specification
- 2.2.1 (programming fundamentals: iteration – count-controlled loops (FOR) and condition-controlled loops (WHILE, DO UNTIL); Boolean operators in conditions).
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.
Pupils need computers for the main task.
Also sold in the Binary, Boolean Logic and Iteration unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
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 GCSE Computer Science (OCR)
See allPupils learn to order the units of data from bit to petabyte and convert between them, stating why all data is stored in binary.
Free sample lessonPupils learn to trace and write FOR loops that use range() with a start, stop and step, and use the loop variable inside the loop.
Pupils learn to convert between denary numbers from 0 to 255 and 8-bit binary using place values.
Written for the specifications named. Not endorsed by or affiliated with any exam board.