Choose exam board for KS4 Computer Science (GCSE)
Choose exam board for KS4 English
Choose exam board for KS4 French
Choose exam board for KS4 Geography
Choose exam board for KS4 German
Choose exam board for KS4 History
Choose tier for KS4 Maths
Choose exam board for KS4 Music
Choose exam board for KS4 Physical education (GCSE)
Choose exam board for KS4 Religious education (GCSE)
Choose exam board for KS4 Spanish

      Lesson details

      Learning outcome

      I can use iteration controlled by a condition to repeat sequences of code.

      Key learning points

      1. Computer programs use iteration to repeat sequences of instructions.
      2. Iteration can be controlled by a condition that determines if the instructions should be repeated.
      3. In Python, condition-controlled iteration is implemented using the 'while' loop command.

      Keywords

      • Iteration - the process of repeating a sequence of instructions within a program loop

      • Condition - an expression that evaluates to True or False

      Common misconception

      A loop will always run at least once.

      A loop only runs if the condition allows it. If the condition isn’t met initially, the code inside won’t run at all.

      Teacher tip

      Demonstrate a loop with a condition that is False from the start and ask students to predict the output. It helps pupils to develop their understanding regardless of if their prediction was correct or not.

      Equipment

      Pupils will need access to a device that can edit and run Python programs. Examples in this lesson use the RPF Code Editor https://oak.link/python-editor

      Licence

      This content is © Oak National Academy Limited (2026), licensed on Open Government Licence version 3.0
      except where otherwise stated. See Oak's terms & conditions
      (Collection 2).

      Lesson video

      Loading...

      Prior knowledge starter quiz

      6 Questions

      Q1.
      What Python function is used to receive data that the user enters?

      Correct Answer: input(), input

      Q2.
      Which of these is a logical operator in Python?

      Correct answer: `and`
      print
      float
      input

      Q3.
      What does the print function do?

      receives user input
      Correct answer: displays output
      ends a program
      compares values

      Q4.
      What does the operator != mean?

      equals
      greater than
      Correct answer: not equals
      less than or equal to

      Q5.
      What is the purpose of the if statement?

      Correct answer: to make decisions
      to repeat code
      to receive input
      to display output

      Q6.
      Match the examples to their descriptions.

      Correct Answer:`5 != 3`,True

      True

      Correct Answer:`int()`,whole number data type

      whole number data type

      Correct Answer:`float()`,decimal number data type

      decimal number data type

      Correct Answer:`if`,decision-making statement

      decision-making statement

      6 Questions

      Q1.
      What Python command is used for condition-controlled iteration?

      Correct Answer: while(), while

      Q2.
      What is iteration in programming?

      a process of storing data
      writing a new program
      comparing two values
      Correct answer: repeating a sequence of instructions

      Q3.
      What does a condition in a while loop do?

      stops the program from running
      Correct answer: decides if the loop should continue
      creates new instructions
      deletes old code

      Q4.
      What happens if the condition in a while loop is False initially?

      Correct answer: the loop doesn’t run at all
      the loop runs once
      the loop runs forever
      the program crashes

      Q5.
      Order the steps of a condition-controlled loop.

      1 - the condition is checked
      2 - if True, the instructions run
      3 - the condition is checked again
      4 - if False, the loop ends

      Q6.
      Write the code to create iteration that will run if the variable num is over 5.

      Correct Answer: while num > 5:, while num>5:

      To help you plan your 10 computer science lesson on: While loops, download all teaching resources for free and adapt to suit your pupils' needs...