Computing · Stage 6

Challenge: Trace & Predict Code

Programs & Judgement · challenge · hand-trace code line by line to predict its output

✦ Computing📘 Stage 6 · S6⏱ ~13 min🧒 Ages 10–12★ Free to start
I can hand-trace code to predict its output.
Kavi the owl for Computing
📖

Kavi Reads the Code Before Pressing Run

Kavi's friend wrote a little program and asked, "What will it print?" Kavi did not press ▶ Run. Instead Kavi hand-traced it — reading each line in order and keeping a little trace table of the values. score = 1 … then +5 → 6 … then a loop that doubled it twice → 12, then 24. "It will print 24," Kavi said. When the program finally ran, the screen showed 24! "A good coder can predict the output of their own code," Kavi hooted, "by tracing it line by line — before the computer ever runs it."

🎓

What your child will learn

1Read the lines, keep a trace tableTo predict what a program prints, you hand-trace it: read every line in order and keep track of each value as it changes. Tap each part to hear its job.
2Follow a total that grows in a loopWatch a value change as each line runs. Press ▶ Run and follow total as Kavi reads the lines — the loop runs its body three times before the last line prints.
3Guess the output, or hand-trace it?You could just guess what a program prints — but a guess goes wrong the moment a loop or an IF is involved. Tracing means following every line in order and keeping a trace table. Tap each way to compare.
4Trace each one, then predict the outputRead each little program, follow the lines in order, and predict what it prints. Reveal to check your trace, then try the next.
🔍

A peek inside

Hand-trace this program: set score = 2 · add 6 · take away 3 · print score. What does it print?
keep the value as each line runs: 2 → 8 → 5

Try this at home: Reading a program line by line, keeping track of the values, to work out its result is called ____.

Ready to play and learn?

Start the free interactive lesson, or print the handout for screen-free play.

Part of Computing · Stage 6 · S6 on KAVI Academy — a secular, whole-child learning platform for ages 5–12.