HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Pseudocode, Trace Tables and Testing
  1. 1Writing pseudocode
  2. 2Trace tables and dry runs
  3. 3Test data and finding errors
  1. Computer Science
  2. /Pseudocode, Trace Tables and Testing
  3. /Trace tables and dry runs

Course 7.2·Lesson 2 of 3

Trace tables and dry runs

A dry run follows an algorithm by hand, one step at a time, without a computer. A trace table records it: one column for each variable, and columns for the prompts and outputs. You complete trace tables for loops and decisions and use them to find what an algorithm does.

about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Pseudocode, Trace Tables and Testing
  1. 1Writing pseudocode
  2. 2Trace tables and dry runs
  3. 3Test data and finding errors

Try the code and the simulations beside the lesson.

Being the computer

How can you be sure an algorithm works before it is a program? You dry-run it: you play the part of the computer, carry out each line in order, and write down every value. A trace table is the table you write it in. The syllabus asks you to record, at each step, the variables, the outputs and the user prompts. A user prompt is a message that asks the user to type something.

A worked trace table

Here is an algorithm that counts the even numbers among four inputs. The inputs are 666, 333, 888 and 555.

pseudocode
Evens ← 0
FOR Index ← 1 TO 4
    OUTPUT "Enter a number"
    INPUT Value
    IF MOD(Value, 2) = 0
      THEN
        Evens ← Evens + 1
    ENDIF
NEXT Index
OUTPUT "Evens: ", Evens
A trace table with the columns Index, Value, Evens and OUTPUT. First row: Evens 0. Index 1: Value 6, Evens 1, OUTPUT "Enter a number". Index 2: Value 3, OUTPUT "Enter a number". Index 3: Value 8, Evens 2, OUTPUT "Enter a number". Index 4: Value 5, OUTPUT "Enter a number". Last row: OUTPUT "Evens: 2".

How do we fill it in?

  1. Evens ← 0 goes in the first row. No other variable has a value yet.
  2. Index becomes 111. A new row starts. The prompt is output, then Value is 666. MOD(6, 2) = 0 is true, so Evens becomes 111.
  3. Index becomes 222. The prompt again, then Value is 333. MOD(3, 2) is 111, so Evens does not change. Leave its cell empty.
  4. Index 333: Value 888, which is even, so Evens becomes 222.
  5. Index 444: Value 555, which is odd. No change.
  6. After the loop, the output is Evens: 2.

A cell is filled only when its value changes. An empty cell means "the same as before". Each pass of a loop usually starts a new row.

Reading a trace table

Look at the last values to find the result, and at the pattern to find the purpose. Here the purpose is: "It inputs four whole numbers and outputs how many of them are even."

A trace table also finds mistakes. Suppose a programmer meant to count numbers greater than 555, but wrote this test.

pseudocode
IF Value > 6
  THEN
    Count ← Count + 1
ENDIF

A dry run with the input 666 shows that 666 is not counted, though 6>56 > 56>5. The trace table points straight at the line to fix.

A loop you cannot count in advance

The algorithm below doubles a value until it reaches 100100100. Try the input 777 by hand: 777, 141414, 282828, 565656, 112112112. That is 444 passes, and the output is 4 112.

pseudocode
INPUT Value
Steps ← 0
WHILE Value < 100 DO
    Value ← Value * 2
    Steps ← Steps + 1
ENDWHILE
OUTPUT Steps, " ", Value

Practise with new numbers

Try it in Python

The grey blocks marked pseudocode are written in the exam style and do not run. The Python box is the same algorithm in Python, and that one runs. This Python program does the even-numbers dry run for you. It prints one row each time round the loop, so you can check your own trace table against it.

Read it first. Then run it. Do the rows match the trace table in the picture?

1. Change the inputs to [2, 4, 7, 9]. Fill in your own trace table first, then run it.

2. Change the test to value % 3 == 0. What does the algorithm count now?

Common mistakes

  • Skipping a row. Write a row for every pass of the loop, even when nothing else changes.
  • Using the new value too early. In Total ← Total + Number, the old Total is used on the right.
  • Forgetting the prompts. In an exam trace table, a prompt such as "Enter a number" goes in the OUTPUT column.
  • Filling every cell. Write a value only when it changes. It keeps the table clear.
  • Stopping a loop one pass too early or too late. Check the condition with the exact value at each pass.

Remember these

  • A dry run follows an algorithm by hand. A trace table records it.
  • Record the variables, the outputs and the user prompts at each step.
  • Write a value only when it changes; a new pass of a loop starts a new row.
  • A trace table shows the result, the purpose and the mistakes of an algorithm.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. In the even-numbers trace table, why is the Evens cell empty in the row where Value is 333?
  1. Dry-run the doubling algorithm with the input 303030. What is output?
  1. Dry-run the doubling algorithm with the input 100100100. How many passes does the loop make?
  1. What is the final value of X? X ← 2, then FOR K ← 1 TO 3, with X ← X + K inside, then NEXT K.
  1. In an exam, a trace table has the columns Count, Total and OUTPUT. The algorithm outputs "Enter a price" before each input. Where do you write that message?

References

  • Cambridge International, IGCSE Computer Science 0478 syllabus (2026, 2027 and 2028), unit 7, part 7: trace tables.

Enroll free in Pseudocode, Trace Tables and Testing

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

Dry-run this algorithm and complete a trace table with the columns A, B and OUTPUT…Medium · High School (9–10) · by StemPy Lab
This algorithm adds up positive numbers until it has three of them…Hard · High School (9–10) · by StemPy Lab
Dry-run this algorithm with the input 586, and then state its purpose.Medium · High School (9–10) · by StemPy Lab
Next: lesson 3Test data and finding errors
← Pseudocode, Trace Tables and Testing
← Writing pseudocodeTest data and finding errors →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place in the course.