Computing · Stage 4

Trace & Predict

Thinking It Through · computational thinking · read a program line by line to predict what it prints

✦ Computing📘 Stage 4 · S4⏱ ~10 min🧒 Ages 8–9★ Free to start
predict a program's output by reading it
Kavi the owl for Computing
📖

Kavi Reads the Program First

Before Kavi pressed ▶ Run, Kavi tried something clever: reading the program first. "If I read each line in order," said Kavi, "I can tell what it will print before I even run it!" The program started score = 2, then added 3, then took 1 away. Kavi pointed at each line and kept the number in mind: 2… 5… 4. "It will print 4," Kavi predicted. Then Kavi ran it — and the screen said 4! "Reading a program and working out its answer is called tracing," Kavi hooted, "and a good coder can predict the output every time."

🎓

What your child will learn

1Read it line by lineTo predict what a program prints, you trace it: read each line in order and keep track of the value as it changes. Tap each part to hear its job.
2Guess the answer, or trace it out?You could just guess what a program prints — but a guess is often wrong. Tracing means reading every line and following the value as it changes. It is slower, but it gives you the right answer every time, even before you run the program.
3Follow the valueWatch a program change one value step by step. Press ▶ Run and follow the number as Kavi reads each line — the last line prints the answer.
🔍

A peek inside

Read this program: set score = 1, then add 4, then add 2, then print score. What does it print?
start at 1, then do each line in order: 1 → 5 → 7

Try this at home: Reading a program line by line to work out its answer is called ____.

Ready to play and learn?

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

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