Tracing and predicting
About this lesson: Tracing and predicting
In short
To trace an algorithm, you follow it line by line and record every change in a trace table. This loop adds up the numbers from 1 to n. Step through and watch the table grow.

What you'll explore
- Trace tables: Follow it line by line
- To trace an algorithm, you follow it line by line and record every change in a trace table. This loop adds up the numbers from 1 to n.
- Predict first: What will it output?
- Programmers predict the output before running a program. This one starts with 3 and doubles it three times.
- Different inputs: Change the input, trace again
- One input tests one case. Try a small start value, then a bigger one. Predict each output in your head first, then run it and check the trace table.
- Check yourself: Trace it
- The program is: INPUT a, then b ← a − 2, then a ← b × 2, then OUTPUT a. The input is 5.
Also in this lesson
- Common mix-ups
- A full trace
- Paper computer
Words to know
- trace
- Follow an algorithm line by line, by hand.
- trace table
- A table showing each value the variables take.
- predict
- Work out what will happen before it happens.
- loop
- Steps that repeat, such as FOR … NEXT or REPEAT.
- bug
- A mistake in an algorithm or program.
Sources
- BBC Bitesize GCSE Computer Science: Trace tables