← IGCSE Computer Science Paper 2

Dry run of an algorithm

Working through an algorithm by hand, line by line, using chosen test data as inputs and recording each step in a trace table, to see what it does and find logic errors without running it.

Understanding Dry run of an algorithm in IGCSE Computer Science Paper 2

What it does: During a dry run you do not type at a keyboard. You choose a test value such as 7 and treat it as the value entered by INPUT. Dry running with Total 10 and Count 2 gives 20 instead of 5, which shows the logic error: the line should use / not *. A dry run is done by hand, without a computer. You follow each line in order to see what the algorithm does. A trace table records each step. Each variable has its own column, and there is an OUTPUT column for anything displayed. Dry runs help you spot logic errors, where the algorithm runs but gives the wrong result. They do not change how fast a program runs.

Common mistakes: A FOR loop needs the keyword TO between the start and end values, so you cannot dry run this line. UNTIL belongs to REPEAT ... UNTIL. It should be FOR Count ← 1 TO 3. When you dry run with a test value such as 35, the algorithm must take that value as input. OUTPUT Temp never stores a value in Temp, so the IF has nothing to test. It should be INPUT Temp.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 71–82) and word search (Modules 71–92).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What is a dry run of an algorithm?
Working through the algorithm by hand, step by step, with chosen input valuesRunning the program on a computer to see if it crashes
Matches
Dry run: skip the loop lines and just write down the final OUTPUT
↓
A dry run must follow every line in order, so skipping the loop lines means that you miss the changing values and any errors
Applying
Meanings
Term
dry run
Meaning
Working through an algorithm by hand, line by line, using chosen test data as inputs and recording each step in a trace table, to see what it does and find logic errors without running it.
Practice
// Dry run with test data 4, 7, 1
Testing
Gaps
// A is done by hand
Check Answer
Spots
1Total ← 0
2FOR Count ← 1 UNTIL 3

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Elephant' badge — OOP Heavyweight, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What is a dry run of an algorithm?
A. Running the program on a computer to see if it crashes
B. Working through the algorithm by hand, step by step, with chosen input values ✓
A dry run is done by hand, without a computer. You follow each line in order to see what the algorithm does.
2. Which one is true about the order you follow in a dry run?
A. Follow the lines in order, one at a time, as the computer would ✓
B. Jump to the lines that look most important first
You must follow the lines in the same order the computer would, including going back around loops and skipping unused IF branches.
3. What do you use as the inputs when you dry run an algorithm?
A. Chosen test data, such as normal, abnormal, extreme or boundary values ✓
B. Random values you make up after finishing the trace
You choose the test data before you start. It acts as the input values, so you can see how the algorithm responds.
4. Where do you record the changing values of variables during a dry run?
A. In a trace table, with a column for each variable and for OUTPUT ✓
B. In a flowchart, with a shape for each variable
A trace table records each step. Each variable has its own column, and there is an OUTPUT column for anything displayed.
5. What is a main purpose of a dry run?
A. To make the program run faster on a computer
B. To find logic errors in an algorithm without running it ✓
Dry runs help you spot logic errors, where the algorithm runs but gives the wrong result. They do not change how fast a program runs.

Match the Pairs

dry run → Working through an algorithm by hand, line by line, with chosen input values, to see what it does without running it on a computer
Total ← 0 FOR Count ← 1 TO 3 Total ← Total + Count NEXT Count → A short algorithm you can dry run: Total goes 0, 1, 3, 6 as you follow each line in order and record the values
A dry run uses chosen test data as the inputs, so you pretend the user typed these values in → INPUT Number // test data: 7
A dry run can find a logic error, because the values you record show the algorithm giving a wrong result → Average ← Total * Count
Dry run: skip the loop lines and just write down the final OUTPUT → A dry run must follow every line in order, so skipping the loop lines means that you miss the changing values and any errors
Dry run: record the values in your head and do not use a trace table → The steps of a dry run should be recorded in a trace table, so that each variable value and OUTPUT is written down and can be checked

Key Term

dry run
Working through an algorithm by hand, line by line, using chosen test data as inputs and recording each step in a trace table, to see what it does and find logic errors without running it.

Fill in the Blanks

1. // A dry run is done by hand
Hint: Type the two-word term for working through an algorithm by hand with chosen test data.
2. Num ← 5 Num ← Num * 2 OUTPUT Num
Hint: Type the arithmetic operator that multiplies, so a dry run gives the new value of Num.
3. IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the keyword that closes the selection so you know which lines to follow in your dry run.
4. FOR Count ← 1 TO 3 OUTPUT Count NEXT Count
Hint: Type the keyword that ends the loop body and sends you back to the next row of the trace table.
5. OUTPUT "Enter a number" INPUT Num OUTPUT Num * 2
Hint: Type the command that reads in a test data value during a dry run.

Spot the Error

Question 1
A Total ← 0
B FOR Count ← 1 UNTIL 3
C Total ← Total + Count
D NEXT Count
E OUTPUT Total
Line B — A FOR loop needs the keyword TO between the start and end values, so you cannot dry run this line. UNTIL belongs to REPEAT ... UNTIL. It should be FOR Count ← 1 TO 3.
Question 2
A OUTPUT Temp
B IF Temp > 30 THEN
C OUTPUT "Hot"
D ELSE
E OUTPUT "Mild"
F ENDIF
Line A — When you dry run with a test value such as 35, the algorithm must take that value as input. OUTPUT Temp never stores a value in Temp, so the IF has nothing to test. It should be INPUT Temp.
Question 3
A Count ← 0
B WHILE Count < 3 DO
C Count ← Count - 1
D ENDWHILE
E OUTPUT Count
Line C — A dry run shows Count going 0, -1, -2 and so on, so Count < 3 is always true and the loop never ends. The line should add 1: Count ← Count + 1.
Question 4
A Total ← 80 + 60
B Count ← 2
C Average ← Total * Count
D OUTPUT Average
Line C — A dry run gives 280 here, but the average of 80 and 60 is 70. The total must be divided by the count, not multiplied. It should be Average ← Total / Count.
Question 5
A Mark ← 50 // 50 or more passes
B IF Mark > 50 THEN
C OUTPUT "Pass"
D ELSE
E OUTPUT "Fail"
F ENDIF
Line B — Dry run with the boundary value 50. The test > 50 is false, so the output is Fail, but the comment says 50 passes. The condition should be IF Mark >= 50 THEN.

Student with a class code? Join your class →