← Years 7–8 Creating Digital Solutions

Tracing selection with a trace table

Check the condition using the current values, record TRUE or FALSE in the trace table, then follow only the branch that is true and skip the other branch.

Understanding Tracing selection with a trace table in Years 7–8 Creating Digital Solutions

What it does: The middle column records TRUE or FALSE for the condition, which shows which branch to follow. 4 > 10 is FALSE, so x <- 0 is skipped and x stays 4 in the trace table. 7 is not greater than 10, so the condition is FALSE. The line inside the if-then block is skipped. 50 >= 50 is TRUE because the >= operator includes equal values. So "Pass" is printed. Recording the condition result does not change any variables. It helps you see and check which path the algorithm took. Always use the current values of variables at that moment in the trace, not old ones.

Common mistakes: The condition uses the assignment arrow ←, which stores a value. A condition has to compare, so it should be: if score ≥ 50 then. Without a comparison there is no TRUE or FALSE to record in the trace table. The assignment is backwards. The variable name goes on the left of the arrow and the value on the right: temp ← 31. Without this, the trace table has no starting value for 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 3–47) and word search (Modules 3–125).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A trace table has x = 7. The algorithm says: if x > 10 then print "big". What do you record for the condition?
FALSE, so skip the print lineTRUE, so print "big"
Matches
x = 3, x > 5 is TRUE, so follow the then branch
↓
The condition was worked out wrongly. 3 > 5 is FALSE, so the then branch should be skipped.
Applying
Meanings
Term
trace an if
Meaning
Check the condition using the current values, record TRUE or FALSE in the trace table, then follow only the branch that is true and skip the other branch.
Practice
score <- 42
Testing
Gaps
Trace row: score=45, score >= 50 is
Check Answer
Spots
1score ← 45
2if score ← 50 then

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

The 'Lion' badge — Inheritance King, 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 trace table has x = 7. The algorithm says: if x > 10 then print "big". What do you record for the condition?
A. TRUE, so print "big"
B. FALSE, so skip the print line ✓
7 is not greater than 10, so the condition is FALSE. The line inside the if-then block is skipped.
2. Which step comes FIRST when you trace an if statement?
A. Check the condition using the current values ✓
B. Run the lines inside the if block
Always evaluate the condition first. Only then do you know which branch to follow.
3. score = 50. The code says: if score >= 50 then print "Pass". What goes in the condition column?
A. FALSE
B. TRUE ✓
50 >= 50 is TRUE because the >= operator includes equal values. So "Pass" is printed.
4. In an if-then-else, the condition is TRUE. What happens to the else branch?
A. It is skipped ✓
B. It also runs after the then branch
Only one branch is followed. When the condition is TRUE, you do the then branch and skip the else branch.
5. age = 12. The code says: if age > 12 then print "Teen" else print "Kid". What is printed?
A. Kid ✓
B. Teen
12 > 12 is FALSE, so skip the then branch and follow the else branch, which prints "Kid".

Match the Pairs

if score >= 50 then → Work out score >= 50 with the current value of score, then write TRUE or FALSE in the trace table
else → The branch that is skipped when the condition was TRUE, and followed only when it was FALSE
The trace table has a column to record the condition result for each check → | age | age >= 13 | message |
If the condition is FALSE, skip the then branch and do not change its variables in the table → x <- 4 if x > 10 then x <- 0
x = 3, x > 5 is TRUE, so follow the then branch → The condition was worked out wrongly. 3 > 5 is FALSE, so the then branch should be skipped.
temp = 30, temp > 25 is TRUE: do then AND else → Both branches were followed. Only the branch that matches the condition result is followed.

Key Term

trace an if
Check the condition using the current values, record TRUE or FALSE in the trace table, then follow only the branch that is true and skip the other branch.

Fill in the Blanks

1. Trace row: score=45, score >= 50 is FALSE
Hint: Type the TRUE or FALSE result of checking the condition with the current value
2. If the condition is FALSE , skip the then branch
Hint: Type the condition result that means the then branch is not followed
3. x=4 | x > 10 | FALSE | then skipped
Hint: Type the word that describes what happens to the then branch when the condition is false
4. age=15 | age >= 18 | FALSE | else runs
Hint: Type the name of the branch that is followed when the condition is false
5. n <- 7 if n > 5 then print "Big"
Hint: Type the keyword that starts a selection and has a condition to check

Spot the Error

Question 1
A score ← 45
B if score ← 50 then
C print "Pass"
D else
E print "Try again"
F end if
Line B — The condition uses the assignment arrow ←, which stores a value. A condition has to compare, so it should be: if score ≥ 50 then. Without a comparison there is no TRUE or FALSE to record in the trace table.
Question 2
A 31 ← temp
B if temp > 30 then
C print "Hot"
D end if
Line A — The assignment is backwards. The variable name goes on the left of the arrow and the value on the right: temp ← 31. Without this, the trace table has no starting value for temp.
Question 3
A age ← 12
B if age < 13 then
C print Junior
D else
E print "Senior"
F end if
Line C — Text to be printed must be inside quotation marks. Without them, Junior looks like a variable name. It should be: print "Junior".
Question 4
A mark ← 72
B if mark ≥ 50 then
C print "Pass"
D end
E print "Done"
Line D — The selection block must be closed with end if. Without it, we can't tell where the true branch stops and where the code that always runs (print "Done") begins.
Question 5
A money ← 20
B if money ≥ 15 then
C money ← money - 15
D print "Bought
E end if
Line D — The text is missing its closing quotation mark. It should be: print "Bought".

Student with a class code? Join your class →