Skip to content

Year 8 · Computing · Python: loops · Lesson 2

While loops

Python while loops: conditions, comparison operators, tracing, infinite loops, input checking, and choosing between for and while.

Whiteboard video lesson: While loops

20-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Explain condition-controlled loops
  • Use comparison operators
  • Trace a while loop
  • Spot and fix infinite loops
  • Choose between for and while loops

The method

  1. Write the starting value.
  2. Check the condition.
  3. If True, run the body and update.
  4. If False, stop.

Key words: while, condition, comparison operator, infinite loop, condition-controlled, trace, input.

Worked examples

The first three practice questions from the lesson, with every step.

Question 1

A while loop repeats while its condition is…?

  1. Step 1: True or False?

Answer: True

Question 2

What does != mean?

  1. Step 1: Not equal to

Answer: Not equal to

Question 3

What does == mean, and how is it different from = ?

  1. Step 1: == compares; = stores (assigns)

Answer: == checks if equal; = assigns a value