← ACARA Digital Technologies Years 7–8

Tracing a decision inside a loop with a trace table

A table with one row per loop repeat. Record the IF condition result, change only the variables the branch updates, copy the rest down, and note any output.

Understanding Tracing a decision inside a loop with a trace table in ACARA Digital Technologies Years 7–8

What it does: The count stays the same on rows where the IF is false and only goes up on rows where it is true, so the repeated numbers show the copy-down rule. The row shows the value of i, the condition being tested and its result. This tells you which branch to follow for that repeat. A trace table has one row per repeat of the loop. Each pass through the loop gets its own row, even if the IF does nothing. Only the variables changed by the branch taken get new values. Everything else is copied down from the row above.

Common mistakes: This trace is for total starting at 0, adding n only when n is even. At n = 2 the condition is Yes, so total = 0 + 2 = 2, not 3. When n is 2, the condition n > 3 is false, so the result column must say No. The row wrongly says Yes, but the score did not change.

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 420–481) and word search (Modules 420–519).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A loop runs 5 times and has an IF inside it. How many rows does the trace table need for the loop?
One row for each repeat, so 5 rowsOne row only, for the whole loop
Matches
Row 2: i = 2, i > 2 is false, total changes from 3 to 5
↓
The condition is false, so the IF branch is skipped. Total should be copied down as 3, not changed to 5.
Applying
Meanings
Term
trace table
Meaning
A table with one row per loop repeat. Record the IF condition result, change only the variables the branch updates, copy the rest down, and note any output.
Practice
SET evens TO 0
Testing
Gaps
Row 1: n = 1, so the condition n > 2 is
Check Answer
Spots
21 | No | 0 | -
32 | Yes | 3 | -

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

The 'Woolly Mammoth' badge — Tundra 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. A loop runs 5 times and has an IF inside it. How many rows does the trace table need for the loop?
A. One row only, for the whole loop
B. One row for each repeat, so 5 rows ✓
A trace table has one row per repeat of the loop. Each pass through the loop gets its own row, even if the IF does nothing.
2. In a trace table for a loop with an IF, what do you record in the condition column?
A. Whether the IF condition was true or false on that repeat ✓
B. The final answer the algorithm will print
The condition column shows the result of the IF test for that repeat (true or false). This tells you which branch ran.
3. Row 3 of a trace table: count = 4, the IF condition (n > 5) is false, and the IF only changes total. What should you do with count in row 3?
A. Copy the value 4 down because the branch did not change it ✓
B. Leave the cell empty or reset it to 0
Unchanged values are copied down. Only variables that the branch taken actually updates get a new value.
4. Which is the correct way to fill in a trace table row when the IF condition is true and the branch says: SET score TO score + 10?
A. Write new values for every variable in the table
B. Write the new score and copy every other variable down unchanged ✓
Only the variables changed by the branch taken get new values. Everything else is copied down from the row above.
5. An algorithm uses a loop with IF number MOD 2 = 0 THEN DISPLAY number. What does the output column show for a repeat where the condition is false?
A. Nothing, because the DISPLAY step did not run ✓
B. The number anyway, because the loop still ran
Output is only recorded when a DISPLAY step runs. If the condition is false and the DISPLAY is inside the IF, the output cell stays empty.

Match the Pairs

FOR i FROM 1 TO 4 / IF i > 2 THEN / total ← total + i → A loop that only adds to total when the condition is true. Rows 1 and 2 leave total unchanged, and rows 3 and 4 change it.
Output column → The column where you write anything the algorithm displays on that repeat, leaving it blank when nothing is shown.
Copy unchanged values down: if the branch does not update a variable, write the same value in the next row. → count: 0, 0, 1, 1, 2
Record the condition result in its own column for each repeat, as true or false, before updating any variables. → i = 3 | i > 2 | true
Row 2: i = 2, i > 2 is false, total changes from 3 to 5 → The condition is false, so the IF branch is skipped. Total should be copied down as 3, not changed to 5.
Stop tracing after the first row because the IF was false → A trace must continue with one row for every loop repeat until the loop ends, even when the IF is false on some rows.

Key Term

trace table
A table with one row per loop repeat. Record the IF condition result, change only the variables the branch updates, copy the rest down, and note any output.

Fill in the Blanks

1. Rule: IF n > 2 THEN total ← total + n Row 1: n = 1, so the condition n > 2 is false
Hint: Type the true/false result you record in the condition column for this row.
2. Rule: IF n > 2 THEN total ← total + n Row 3: n = 3, total before = 0 total after = 0 + 3
Hint: Type the value of n that the true branch adds to total.
3. Rule: IF n > 2 THEN total ← total + n Row 4: n = 2, n > 2 is false total before = 5, total after = 5
Hint: Type the number copied down when the branch does not run.
4. IF n MOD 2 = 0 THEN OUTPUT n Row n = 4: output column shows 4
Hint: Type the keyword that sends a value to the output column.
5. Final row: count = 3, total = 9 Final values are read from the last row
Hint: Type the word for which row of the trace table gives the values after the loop.

Spot the Error

Question 1
A n | even? | total | output
B 1 | No | 0 | -
C 2 | Yes | 3 | -
D 3 | No | 2 | -
E 4 | Yes | 6 | -
Line C — This trace is for total starting at 0, adding n only when n is even. At n = 2 the condition is Yes, so total = 0 + 2 = 2, not 3.
Question 2
A n | n > 3? | score
B 1 | No | 0
C 2 | Yes | 0
D 3 | No | 0
E 4 | Yes | 4
F 5 | Yes | 9
Line C — When n is 2, the condition n > 3 is false, so the result column must say No. The row wrongly says Yes, but the score did not change.
Question 3
A SET total TO n
B FOR n FROM 1 TO 4
C IF n > 2 THEN
D SET total TO total + n
E END IF
F END FOR
Line A — total must be set to 0 before the loop, so the first trace row starts from a known value. n has no value yet, so it should be SET total TO 0.
Question 4
A FOR n FROM 1 4
B IF n > 2 THEN
C OUTPUT n
D END IF
E END FOR
Line A — A FOR loop needs the word TO between the start and end values. It should be FOR n FROM 1 TO 4, which gives four rows in the trace table.
Question 5
A n | n is even? | evens
B 1 | No | 0
C 2 | Yes | 1
D 3 | No | 2
E 4 | Yes | 2
F Final evens = 2
Line D — At n = 3 the condition is No, so the branch is skipped and evens is not changed. The unchanged value 1 must be copied down, not changed to 2.

Student with a class code? Join your class →