Single lesson · Key Stage 3

Condition-controlled loops (while) – Year 8 Computing lesson

Pupils learn to write a while loop that repeats until a condition is met, predict how many times it runs and spot an infinite loop.

Also in a bundle Python: Iteration and Boolean Operators – Year 8 Computing lessons 6 lessons for £20 · save 16% on buying separately

Lesson 4 of 6 in unit 8.1 Python: Iteration and Boolean Operators, taught in Year 8, Autumn 1. It answers one big question: How can a program keep repeating until something changes?

By the end, pupils can write a while loop that repeats until a condition is met, predict how many times it runs and spot an infinite loop.

The Build (the main task)
Write a program that keeps asking the user for a new password while it is shorter than 8 characters, counts the attempts, then says how many tries it took.
Support version
Parsons problem: the lines of the while program are jumbled, with one extra line that would make an infinite loop.
Challenge
Stop after 5 attempts as well, using AND or OR in the while condition, and explain why.
Real-world link
Sign-up pages keep asking until you choose a password that meets the rules; nobody knows in advance how many tries it will take.
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 will stop by itself even if nothing inside it changes the condition”; “A while loop always runs at least once”.
National Curriculum
NC3 (two or more languages, at least one textual; data structures; modular programs with procedures or functions); NC4 (boolean logic (AND, OR, NOT) in circuits and programming; binary numbers, addition and conversion).

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 Python
Iteration and Boolean Operators 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 KS3 Computing

See all

Written for the specifications named. Not endorsed by or affiliated with any exam board.