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 trace tables to trace how variables change in a while loop.

      Key learning points

      1. Trace tables are used to record how the values of variables change during the execution of a program.
      2. Trace tables and while loops help debug programs.

      Keywords

      • Trace table - a tool used to track the values of variables and the flow of execution in an algorithm or program, step by step

      • Condition - an expression that evaluates to True or False

      Common misconception

      The condition in a while loop is only checked once. The loop will always run a fixed number of times.

      Remind students that the condition is checked before each iteration. The loop repeats only while the condition is True. Variable changes inside the loop affect whether it continues or stops.

      Teacher tip

      Model how the condition is re-evaluated with each loop cycle. Walk through a trace table together, updating the variable and condition step by step.

      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 is iteration in programming?

      Correct answer: the process of repeating a sequence of instructions within a program loop
      writing a program without loops
      running a program once
      debugging a program

      Q2.
      What does a condition in programming evaluate to?

      a string
      a number
      Correct answer: True or False
      a list

      Q3.
      What is the keyword for condition-controlled iteration in Python?

      Correct Answer: while, while()

      Q4.
      When does a while loop stop executing?

      when the program ends
      Correct answer: when the condition becomes False
      after 10 iterations
      when all variables are used

      Q5.
      What happens if the condition in a while loop is always True?

      the program crashes
      the loop never runs
      Correct answer: an infinite loop occurs
      the loop runs once

      Q6.
      Arrange the steps of a while loop.

      1 - Evaluate the condition.
      2 - Execute the loop body.
      3 - Update variables.
      4 - Repeat if condition is True.

      6 Questions

      Q1.
      Match the term to its definition.

      Correct Answer:trace table,tracks variable values step by step

      tracks variable values step by step

      Correct Answer:condition,logical expression controlling program flow

      logical expression controlling program flow

      Correct Answer:while loop,repeats code while a condition is True

      repeats code while a condition is True

      Correct Answer:debugging,fixing errors in a program

      fixing errors in a program

      Q2.
      What is the purpose of a trace table?

      to write new code for a program
      to display the program's output
      Correct answer: to track the values of variables during program execution
      to compile a program

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

      Correct answer: the loop does not run
      the loop runs once
      the loop runs indefinitely
      the loop skips to the next condition

      Q4.
      When is the condition in a while loop checked?

      only at the start of the program
      only at the end of the program
      Correct answer: before each iteration
      after each iteration

      Q5.
      What does a trace table record?

      the errors in a program
      the steps to write a program
      standard messages like "Welcome"
      Correct answer: the changes in variable values

      Q6.
      Arrange these steps in the correct order for using a trace table.

      1 - Write the program.
      2 - Create a trace table.
      3 - Record variable changes.
      4 - Debug the program.

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