← IGCSE Computer Science Paper 2

Completing a full trace table for a dry run

A table for a dry run: follow the algorithm line by line with the given inputs, writing each variable, output and prompt in the order it happens, then check the final values.

Understanding Completing a full trace table for a dry run in IGCSE Computer Science Paper 2

What it does: A dry run of this loop tests Num MOD 2 = 0 on every pass, so Total only changes for Num = 2 and Num = 4, ending at 6. The last value written in the Total column is 6, and this is what the OUTPUT column shows at the end of the dry run. A dry run copies what the computer does. Each row is a step in the order of execution, so you can't finish one column and then start the next. Only the lines that really run create new values. If the condition is false, the THEN part is skipped (or the ELSE part runs instead).

Common mistakes: A FOR loop uses TO to set its end value: FOR Count ← 1 TO 3. Without the correct header you cannot work out the rows of a trace table. An IF condition must end with THEN. It should be IF N MOD 2 = 0 THEN, so you can trace which rows change Count.

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 83–92) 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
In which order do you fill in the rows of a trace table?
One variable column at a time, from left to rightIn the order the algorithm runs, line by line
Matches
Num=1, Total=1 | Num=2, Total=3 | Num=3, Total=6 (for a loop with an IF that only adds even numbers)
↓
The IF condition was not tested, so every Num was added to Total. Only the even values (2) should have changed Total.
Applying
Meanings
Term
trace table
Meaning
A table for a dry run: follow the algorithm line by line with the given inputs, writing each variable, output and prompt in the order it happens, then check the final values.
Practice
Total ← 0
Testing
Gaps
← Total + Count
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 'Thorny Devil' badge — Detail Master, 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. In which order do you fill in the rows of a trace table?
A. One variable column at a time, from left to right
B. In the order the algorithm runs, line by line ✓
A dry run copies what the computer does. Each row is a step in the order of execution, so you can't finish one column and then start the next.
2. A variable changes value during the dry run. What do you do in its column?
A. Cross out the old value and replace it in the same row
B. Write the new value in the next row and keep the old values ✓
The column shows the history of the variable. Keeping the old values lets you check each step later.
3. When does an OUTPUT line get written in the OUTPUT column?
A. On the row where the OUTPUT statement runs ✓
B. All together in the last row after the algorithm ends
Outputs go in the order they happen. An OUTPUT inside a loop appears once for every pass.
4. The algorithm has OUTPUT "Enter a number" then INPUT Num. How do you record this?
A. The prompt goes in the OUTPUT column and the typed value goes in the Num column ✓
B. Neither is recorded because the user is typing, not the program
Prompts are outputs, so they go in the OUTPUT column. The value the user enters is stored in the variable, so it goes in that variable's column.
5. The IF condition is false. What do you do in the trace table?
A. Skip the THEN lines, so no values change inside them ✓
B. Run the THEN lines anyway and record the changes
Only the lines that really run create new values. If the condition is false, the THEN part is skipped (or the ELSE part runs instead).

Match the Pairs

Total | Count | OUTPUT (column headings) → The trace table has one column for each variable and one for OUTPUT, so every change can be recorded.
FOR Count ← 1 TO 3 (one new row each time a value changes) → Fill in the rows in the same order the algorithm runs, so each loop pass adds new rows in sequence.
Work through a loop with an IF: on each pass, test the condition and only update the variable when it is true → FOR Num ← 1 TO 4 IF Num MOD 2 = 0 THEN Total ← Total + Num ENDIF NEXT Num
After the last row, check the final values: the last entry in each column is the final value of that variable and the OUTPUT column shows what was displayed → Total ← 0 FOR Num ← 1 TO 3 Total ← Total + Num NEXT Num OUTPUT Total
Num=1, Total=1 | Num=2, Total=3 | Num=3, Total=6 (for a loop with an IF that only adds even numbers) → The IF condition was not tested, so every Num was added to Total. Only the even values (2) should have changed Total.
Row 1: OUTPUT 6, Row 2: Total ← 0 (for an algorithm that sets Total to 0, then adds, then outputs) → The rows are out of order. The OUTPUT was written before the assignments that create the value had been traced.

Key Term

trace table
A table for a dry run: follow the algorithm line by line with the given inputs, writing each variable, output and prompt in the order it happens, then check the final values.

Fill in the Blanks

1. FOR Count ← 1 TO 3 Total ← Total + Count NEXT Count
Hint: Type the variable that gets a new value in every row of the trace table (the running total).
2. IF Number MOD 2 = 0 THEN OUTPUT "Even" ENDIF
Hint: Type the operator that gives the remainder after division, used to decide if the OUTPUT column gets a value.
3. WHILE Total < 10 DO Total ← Total + 4 ENDWHILE
Hint: Type the keyword that starts a loop that keeps adding trace table rows while its condition is true.
4. OUTPUT "Enter a number" INPUT Number OUTPUT Number * 2
Hint: Type the command that reads in the given test value which you record in the trace table.
5. FOR Count ← 1 TO 4 IF Count > 2 THEN OUTPUT Count NEXT Count
Hint: Type the keyword that follows the condition, so you know when to fill the OUTPUT column.

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 uses TO to set its end value: FOR Count ← 1 TO 3. Without the correct header you cannot work out the rows of a trace table.
Question 2
A Count ← 0
B FOR N ← 1 TO 5
C IF N MOD 2 = 0
D Count ← Count + 1
E ENDIF
F NEXT N
Line C — An IF condition must end with THEN. It should be IF N MOD 2 = 0 THEN, so you can trace which rows change Count.
Question 3
A Total ← 0
B Num ← INPUT
C WHILE Num <> 0 DO
D Total ← Total + Num
E INPUT Num
F ENDWHILE
Line B — Reading a value uses the INPUT command followed by the variable name: INPUT Num. In the trace table the input value goes in the Num column.
Question 4
A DECLARE Total INTEGER
B Total ← 0
C FOR N ← 1 TO 4
D Total ← Total + N
E NEXT N
Line A — A declaration needs a colon between the identifier and the data type: DECLARE Total : INTEGER. Each declared variable gets a column in the trace table.
Question 5
A Count = 0
B REPEAT
C Count ← Count + 1
D UNTIL Count = 3
E OUTPUT Count
Line A — Assigning a starting value uses the assignment arrow: Count ← 0. The = sign is a comparison, not an assignment. The first trace table row shows Count as 0.

Student with a class code? Join your class →