Study Guide Instructor view
Trace Tables and Dry Runs
Teaching notes for Lesson 5.7, with controls for presenting it.
Keep this page on your own screen. Share only the lesson window. The lesson window holds no teaching notes, so sharing it cannot show them.
Presenting
- Open the lesson in its own window and share that window, not this one.
- Use Next and Previous here, or the lesson’s own, to move through the lesson. Next reveals one thing at a time: the next idea, or the answer to the question on screen, then the next step. Previous takes the last reveal back. The line below says what is on screen and what Next will show.
- Reveal hints and answers when the class is ready, and reset a demonstration before using it again.
The controls need JavaScript and a browser that supports BroadcastChannel. Without them, open the lesson in presentation mode and use its own controls.
The two windows talk to each other only inside this browser, on this device. Nothing is sent to a server, and no account is needed. A second device (a phone or another tablet) cannot follow the lesson window yet.
Now on the lesson window
- On screen
- Next teaching point
Guidance for this point
Lesson plan
- Level
- Intermediate
- Time
- About 75 minutes; the steps below add up to 75
Pupils are given a program on paper with no computer and asked how they would find out what it does, which makes the trace table a method they invent before it is named. They then trace a WHILE loop, a quiz with prompts and typed values, and a loop with a nested IF, use a trace to discover an algorithm's purpose, use a trace to find the faulty line, and finally write and trace a program of their own. The central habit is working from the row above and tracing what the lines say, not what the programmer meant.
Objectives
- Complete a trace table for a program with a loop, showing the variables, the outputs and the user prompts at each step
- Trace a loop that has an IF statement, including one nested inside another, to the end
- Use a trace to say what an unfamiliar algorithm is for
- Use a trace to find the line that makes a program give the wrong answer, and correct it
- Design the columns of a trace table for a program of your own
Before the lesson
- Mini whiteboards, one per pupil, for predictions and for filling in a trace row at a time.
- Copy the arcade program and a blank trace table (Row, Tickets >= 3?, Tickets, Played, OUTPUT) onto the board before the lesson.
- Prepare the quiz app, greenhouse and faulty pass-counting programs on separate slides or board areas so that you can trace each live.
- Optional: sticky notes or counters to stand for the variables so that pupils can move values on the table.
Steps
Introduction Opening
On the lesson window now
On screen: the lesson’s title, module and number; Next adds its objectives and key terms, as the lesson page lists them; Next again begins the first step.
Objectives on screen
- Complete a trace table for a program with a loop, showing the variables, the outputs and the user prompts at each step
- Trace a loop that has an IF statement, including one nested inside another, to the end
- Use a trace to say what an unfamiliar algorithm is for
- Use a trace to find the line that makes a program give the wrong answer, and correct it
- Design the columns of a trace table for a program of your own
Purpose: Pupils are given a program on paper with no computer and asked how they would find out what it does, which makes the trace table a method they invent before it is named. They then trace a WHILE loop, a quiz with prompts and typed values, and a loop with a nested IF, use a trace to discover an algorithm's purpose, use a trace to find the faulty line, and finally write and trace a program of their own. The central habit is working from the row above and tracing what the lines say, not what the programmer meant.
1. A program with no computer Think 4 min
On the lesson window now
Purpose: Pupils work out for themselves that following a program by hand means writing down variable values as they change, before the term trace table is given.
Ask
- How would you find out exactly what this program outputs with only a pencil?
- What would you write down as you go?
Responses to expect
- Follow it one line at a time
- Write down what Tickets and Played hold each time
- Some will just guess the final answer
Misconceptions to challenge
- A learner may believe: “You can see what a program does by reading it once.” Respond: Ask the pupil to say what Tickets holds after the third pass without writing anything down. The values change faster than memory.
Checking understanding: Pupils write on a mini whiteboard the two things they would record: variables and output.
Depending on the answers
- If pupils only mention the output: ask what is needed to work out the next output, and hence which values must be written down between lines.
English as an additional language
- Check arcade, tickets and program on paper; show the sheet with the code printed on it.
Discussion pause: Thirty seconds of silent thinking, then pairs agree on what they would write down.
In the lesson window
- Think it through: You have a pencil and the sheet, and you want to know exactly what this program would output. How would you find out? What would you write down as you went?
2. Writing the steps down Predict 12 min
On the lesson window now
Purpose: Pupils predict the arcade program's result, then trace it row by row, learn why a cell is left empty when nothing changes, and distinguish a dry run from a trace table.
Ask
- Before tracing: how many games are counted and what is the last number of tickets output in the loop?
- In the Pass 4 row, why are Tickets and Played empty?
- On Pass 2, which value of Tickets does the subtraction use?
Responses to expect
- 3 games and a last number of 1
- The loop body did not run
- The 7 from Pass 1
Misconceptions to challenge
- A learner may believe: “A value that does not change should be written again.” Respond: A trace table records changes; a blank cell means unchanged.
- A learner may believe: “The final row shows the loop running a fourth time.” Respond: The test is made, found false, and the body is skipped; the row records only the test and the output after the loop.
- A learner may believe: “Variables become empty when a loop ends.” Respond: A variable keeps its value; Played is still 3 when Games: 3 is output.
- A learner may believe: “Jump to the answer without every row.” Respond: Each value comes from the row above; a shortcut can be right but cannot be trusted.
- A learner may believe: “Dry run and trace table are the same.” Respond: A dry run is what you do; a trace table is the record you write.
On the board or with the pen
- Draw the table with its five columns and fill it in with the pupils row by row, writing the test result before the new values; leave the cells that do not change empty and circle the empty cells in Pass 4.
What learners should notice
- The test for the loop is made at the top of each pass, before anything changes.
Checking understanding: The empty-cells check: the options are that the trace is unfinished, the body did not run, or variables empty when loops end. Each wrong option is a different misreading of a blank.
Depending on the answers
- If pupils write 0 or 3 in the empty cells: ask them what line of the program changes Tickets on Pass 4, and whether it ran.
- If the table is done quickly: ask them to trace the same program with 12 tickets and predict the games before tracing.
Support
- Provide the table with the first pass filled in and the test column completed.
Stretch
- How many tickets would give exactly four games and no tickets left over?
English as an additional language
- Check pass, row and unchanged; point to a row as you say each.
In the lesson window
- Think it through: Before tracing, predict: how many games does the arcade program count, and what is the last number of tickets it outputs inside the loop?
- Check your understanding: In the Pass 4 row, the Tickets and Played cells are empty. Why?
3. Prompts and typed values Discover 10 min
On the lesson window now
Purpose: Pupils predict the score of a quiz with a nested IF, then record prompts and typed answers in the trace table.
Ask
- A player types A, B, X, A: what is the final score, and which answers reach the inner IF?
- Where does the text Answer to question 2 belong in a trace table?
Responses to expect
- 3
- B and X reach the inner IF
- In the output column, on the row for question 2
Misconceptions to challenge
- A learner may believe: “A trace table records only variables.” Respond: The syllabus asks for outputs and prompts too; the text the user sees is an output.
- A learner may believe: “B takes one off.” Respond: Only X takes one off; B is not A and not X, so Score is unchanged.
- A learner may believe: “The prompt goes in the Score column.” Respond: A variable's column holds its value; a prompt does not change Score.
On the board or with the pen
- Write the quiz trace with columns Row, OUTPUT, Answer typed and Score, and fill in Score for each answer, circling the row where the inner IF decides.
Checking understanding: The prompt-row check: the nowhere and Score-column options reveal pupils who record only variables or put text in the wrong column.
Depending on the answers
- If pupils record the prompt in the wrong column: ask which of the program's lines displays it, and what kind of line that is.
- If pupils trace easily: ask them to find an answer string that leaves Score at 0 after four questions.
Support
- Give the quiz table with the OUTPUT and Answer columns filled in so that only Score is traced.
Stretch
- Make the program remove 1 point for an answer X only if Score is above 0. Where does the extra test go?
English as an additional language
- Check prompt and typed; mime typing and reading text on a screen.
In the lesson window
- Think it through: A player types A, B, X and A for the four questions. Predict the final score. Which of the four answers uses the inner IF?
- Check your understanding: Where does the text “Answer to question 2” belong in a trace table?
4. Tracing a loop with a choice inside it Explain 12 min
On the lesson window now
Purpose: Pupils predict what two counters in a nested-IF loop count, read a worked trace, and then trace a greenhouse program with a column for each test.
Ask
- What do EvenTotal and BigEvens each count?
- For the temperature 18, are both tests made, and what happens?
- Why is the inner test marked Not reached for 12?
Responses to expect
- Total of the even numbers and how many are above 5
- Both are made; outer true, inner false; Mild goes up
- The outer test is false, so the inner IF is never reached
Misconceptions to challenge
- A learner may believe: “Both counters go up for 18.” Respond: An inner IF with ELSE runs one branch only; 18 is below 25, so Mild goes up.
- A learner may believe: “The inner test is made even if the outer is false.” Respond: The inner IF is inside the outer one; if the outer is false, it is skipped.
- A learner may believe: “25 is only Mild because it is on the boundary.” Respond: The test is >=, so 25 is Hot.
- A learner may believe: “Only the outer test needs a column.” Respond: Each test decides whether lines run, so each earns a column.
On the board or with the pen
- Trace the even-numbers program with columns Number, outer test, inner test, EvenTotal, BigEvens. Write the greenhouse table beside it and mark the empty (not reached) cells in a different colour.
Follow-up questions
- Which temperatures in 12, 27, 18, 25 and 31 would change if the outer test were > 15?
Checking understanding: The inner-test check: the first option ignores that the outer test is true for 18; the second thinks both counters rise. Look for pupils who write Not reached correctly for 12.
Depending on the answers
- If pupils fill the inner test column for 12: ask whether the line that makes that test is carried out when the outer test is false.
- If pupils are secure: ask them to choose five temperatures that give 2 hot days and 2 mild days.
Support
- Provide the greenhouse table with the outer test column filled in.
Stretch
- Add a third level: temperatures of 35 or more are extreme. How many columns now?
English as an additional language
- Check inner and outer; draw a small box inside a big box.
In the lesson window
- Think it through: Look at the program in the worked example below before reading the trace. What do you think EvenTotal and BigEvens each count?
- Check your understanding: For the temperature 18, which statement about the program is true?
5. What is this algorithm for? Discover 8 min
On the lesson window now
Purpose: Pupils guess and then trace to find the purpose of an unfamiliar program, and describe it in a sentence without listing lines.
Ask
- Without tracing, what do you think this program does with the number typed?
- It outputs 9 for 3, 16 for 4 and 25 for 5: what is it for?
Responses to expect
- Adds the number to itself that number of times
- Squares the number by repeated addition
Misconceptions to challenge
- A learner may believe: “It doubles the number.” Respond: Compare each output with the number: 3 gives 9, not 6.
- A learner may believe: “It adds the numbers from 1 to the number.” Respond: For 3 that would be 6. What is actually added on each pass?
- A learner may believe: “The output is the number of passes.” Respond: The passes are 3, 4, 5; the outputs are 9, 16, 25.
On the board or with the pen
- Trace the program for 3 with Step and Result columns: 3, 6, 9. Add 4 and 5 as one-line results beside it, then write the pattern 3 x 3, 4 x 4, 5 x 5.
Checking understanding: The purpose question has four options, one for each plausible wrong reading of the pattern: doubling, adding 1 to n, counting passes and the correct squaring.
Depending on the answers
- If pupils choose double: ask them to trace 3 and compare 9 with 3 doubled.
- If pupils name the purpose quickly: ask for a one-line description they could give an examiner without listing the lines.
Support
- Give the three outputs as a small table and ask pupils to spot the pattern.
Stretch
- What would the program output for 0? Is that sensible?
In the lesson window
- Think it through: Without tracing yet, what do you think this program does with the number typed? Make a guess, then trace it for the number 3.
- Check your understanding: The program outputs 9 for 3, 16 for 4 and 25 for 5. What is the algorithm for?
6. Finding the line that is wrong Apply 9 min
On the lesson window now
Purpose: Pupils trace a faulty pass-counting program on test data that includes the boundary mark, find the first row where it disagrees with the intention, and decide the fix.
Ask
- Trace the program for 62, 50 and 38: what does it output?
- On which row do the program and the intention first disagree?
- What is the fix?
Responses to expect
- Passes: 1
- Row 2, the mark 50
- Change the condition to >=
Misconceptions to challenge
- A learner may believe: “Row 2 should say Yes because 50 is a pass.” Respond: Trace what the line says: 50 > 50 is false, even though the programmer meant it to count.
- A learner may believe: “Passes should start at 1.” Respond: Row 1 gives the right answer for 62. Look for the first row that goes wrong.
- A learner may believe: “38 should add 1 to Passes.” Respond: 38 is below the pass mark; the boundary mark is 50.
On the board or with the pen
- Write the trace with expected values in a second column and mark the first row where the two columns disagree with a star.
What learners should notice
- The boundary mark exposes the fault where 62 and 38 do not.
Checking understanding: The fix-the-line question: each wrong option points at a different row, so which row a pupil picks shows whether they traced honestly.
Depending on the answers
- If pupils choose row 1: ask them to compare the Passes column with what they expect after 62.
- If pupils are secure: ask why 62 and 38 alone would not have found the fault, and what test data would.
Support
- Provide the trace with an Expected column so that pupils compare column by column.
Stretch
- Write three test marks that would show the fault in a program that uses > 50 for a pass of 50 or more, and three that would not.
English as an additional language
- Check fault, expected and boundary; show the marks on a number line with 50 marked.
In the lesson window
- Apply it: Compare the trace with the expected answer. On which row do the program and the intention first disagree, and what is the fix?
7. Write it, then trace it Apply 12 min
On the lesson window now
Purpose: Pupils write a short step-counting program with prompts, say which columns its trace needs, and trace it for four days including a boundary day.
Ask
- Write the pseudocode with a prompt before each input.
- Which columns does a trace table need?
- For 9000, 7500, 8000 and 12000: what are Total and GoalDays after each day?
Responses to expect
- Day, OUTPUT, Steps, Total, GoalDays
- Total 36500 and GoalDays 3 at the end
- Some forget the 8000 day counts
Misconceptions to challenge
- A learner may believe: “The 8000-step day does not count because it is not above the goal.” Respond: The goal is 8000 or more, so >= includes it.
- A learner may believe: “The trace needs a column for Day only.” Respond: Every variable that changes, and the output and typed value, need columns.
- A learner may believe: “Total and GoalDays start inside the loop.” Respond: Both are set to 0 before the loop.
On the board or with the pen
- Draw the table with the columns pupils choose and fill it in row by row with the four days.
Checking understanding: Collect the pseudocode and the tables: check the starting values, the >= test, and whether the prompts are in the OUTPUT column.
Depending on the answers
- If pupils omit the prompt column: ask which line of their program displays the prompt and where it should appear in the table.
- If pupils finish early: ask them to alter the program to also output the average steps and add one column to their table.
Support
- Provide the program and ask pupils to write only the columns and the first row.
Stretch
- Change the goal to 10000 and say which rows of the trace change.
In the lesson window
- Think it through: Write the pseudocode, including a prompt before each input. Then say which columns a trace table for it needs, and fill in the table for the days 9000, 7500, 8000 and 12000.
8. Show what you know Consolidate 8 min
On the lesson window now
Purpose: Pupils explain why tracing is still useful with a computer, and choose the columns for a three-mark average program, before the summary.
Ask
- Why is a trace table useful when a computer could run the program? Give two jobs.
- Which columns record everything for the average of three marks with a Mark? prompt?
Responses to expect
- It shows where a value goes wrong, shows the purpose of an unfamiliar algorithm, finds the faulty line, or checks a design
- Mark, Total and OUTPUT, with the prompt in OUTPUT
Misconceptions to challenge
- A learner may believe: “Only Total needs a column.” Respond: The typed value is a variable and the prompts and the average are outputs.
- A learner may believe: “Outputs are not part of the algorithm.” Respond: They are its visible result; the prompt would not be recorded anywhere.
Checking understanding: Collect the explanations: two distinct jobs, one of which should relate to finding the line at fault.
Depending on the answers
- If pupils choose Total only: ask them to list everything the program displays or reads, and see which of them has a column.
- If several are unsure of prompts: begin the next lesson with a quick trace in which one prompt row is wrong.
In the lesson window
- Think it through: Explain to a friend why a trace table is useful even when you have a computer that can run the program. Give two different jobs it does.
- Apply it: A program reads three marks, outputs the prompt “Mark?” before each, totals them and then outputs the average. Which set of columns gives a trace table that records everything the syllabus asks for?
Lesson recap Closing
On the lesson window now
On screen: the lesson’s objectives again; Next adds the closing question, which asks the class to explain each one in their own words without looking back. It says nothing about what anyone has learnt: use the answers to decide what to revisit.
Points to listen for
- A dry run follows an algorithm by hand with chosen data; a trace table is the record of it.
- Work from the row above; write a value only when it changes and leave other cells empty.
- Show nested tests in columns; an inner IF is reached only when the outer one is true.
- Trace two or three values to find an algorithm's purpose, then state it in a sentence.
- To find an error, trace what the lines say; the first row that disagrees shows the line to fix, and boundary values are the best test data.
Consolidation
- A dry run follows an algorithm by hand with chosen data; a trace table is the record of it.
- Work from the row above; write a value only when it changes and leave other cells empty.
- Show nested tests in columns; an inner IF is reached only when the outer one is true.
- Trace two or three values to find an algorithm's purpose, then state it in a sentence.
- To find an error, trace what the lines say; the first row that disagrees shows the line to fix, and boundary values are the best test data.