Community resourceWorksheet

J277 2.1.2 Trace tables: sequence and selection

Part 2 of 3 · J277 2.1.2 · Tracing and refining algorithms

Trace tables for sequence and selection, marked automatically row by row.

Students will:

  • record variable and output changes in execution order
  • decide when a trace-table box should be left empty
  • trace a program containing a decision
  • use a completed trace to explain what a program produces
  • apply the method to an exam-style question

Inside: 3 explanation cells, 3 trace tables, 2 multiple-choice questions and 2 written answers. 6 author-set marks plus the trace-table rows, about 45 minutes.

Series: J277 2.1.2 · Tracing and refining algorithms, part 2 of 3.

Shared by Coding PathwayVerified teacher

  • 10 cells
  • About 45 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026
  • Updated 9 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Trace tables: sequence and selection

A trace table records how variables and outputs change while an algorithm executes. Trace in execution order. Enter a new value only when the algorithm changes that value; an empty box means unchanged unless the question says otherwise.

Multiple choice1 mark

When should a new value normally be entered in a trace-table variable column?

  • AOnly when that variable changes on the traced step
  • BOn every visible row, whether it changes or not
  • COnly at the end
  • DWhenever another variable changes

A dependable method

Read one executable statement at a time. Calculate its effect using the current values, record only the changes caused by that statement, and record output when print executes. For selection, evaluate the condition using the values at that point, then follow only the selected branch.

Worked trace

For this short algorithm:

x = 2
x = x + 3
print(x)

one suitable trace is:

Statement completedxOutput
x = 22
x = x + 35
print(x)5

The blank cells mean that the value did not change on that step. The output is recorded only when the print statement executes.

Trace table5 marks

Complete the trace table for this sequence of assignments.

Work down the algorithm one statement at a time. Leave a cell blank when its value is unchanged.

Use one row for each line as it runs, in the order the lines run. Fill in a box only when that value changes on that row, and leave the rest blank. Put the line number from the listing in the Line column.

AlgorithmExam reference language
  1. price = 6
  2. quantity = 4
  3. total = price * quantity
  4. total = total + 2
  5. print(total)
Trace table with 5 columns
RowLinepricequantitytotalOutput
1
2
3
4
5
6
7
Multiple choice1 mark

In the first trace, what is the final output?

  • A24
  • B26
  • C8
  • D64
Trace table4 marks

Complete the trace table. Pay particular attention to the boundary value.

Evaluate the condition before choosing one branch. Do not trace the branch that is skipped.

Use one row for each line as it runs, in the order the lines run. Fill in a box only when that value changes on that row, and leave the rest blank. Put the line number from the listing in the Line column.

AlgorithmExam reference language
  1. score = 50
  2. if score >= 50 then
  3. result = "Pass"
  4. else
  5. result = "Review"
  6. endif
  7. print(result)
Trace table with 5 columns
RowLinescoreresultscore >= 50Output
1
2
3
4
5
6
Trace table8 marks

Trace this two-stage selection and record the one printed output.

These are two separate if statements. Both conditions can be true.

Use one row for each line as it runs, in the order the lines run. Fill in a box only when that value changes on that row, and leave the rest blank. Put the line number from the listing in the Line column.

AlgorithmExam reference language
  1. age = 14
  2. member = True
  3. price = 12
  4. if age < 16 then
  5. price = price - 3
  6. endif
  7. if member then
  8. price = price - 2
  9. endif
  10. print(price)
Trace table with 7 columns
RowLineagememberpriceage < 16memberOutput
1
2
3
4
5
6
7
8
9
10
Written answer2 marks

Explain why both discounts are applied in the final trace rather than only the first discount.

Refer to the two separate if statements and their conditions.

Students type their answer here.

Written answer2 marks

A student copies the current value into every blank trace-table cell. Explain why this is unhelpful when the instruction says that a blank means unchanged.

Link the convention to seeing exactly when a value changes.

Students type their answer here.

Exam habit

Do not work out the whole program mentally and write only the final values. The marks are often for intermediate changes and outputs. Use the exact algorithm provided, even if you can imagine a shorter solution.