Comet slaps a page onto the workbench. "Beacon's first real routine! Five lines. It shows 30. I checked it in my head."
Wren reads it slowly, one finger on each line. "What do you notice about line three?"
"It just adds some water," Comet says. "No big deal."
Nova hovers over the page and lights up a grid. "Let's debug together," she says.
"One column for each variable, one row for each line. Write down what changes, and only what changes."
Comet hands you a pad of sticky notes. "Fine. Developer, prove me right."
Hand tracing means running a program yourself, on paper, one line at a time.
You will trace Comet's routine in a trace table and find out what it really displays.
A trace table has one row for each line and one column for each variable.
waterLevel ← 40 lightLevel ← 70 waterLevel ← waterLevel + 15 lightLevel ← lightLevel - waterLevel DISPLAY(lightLevel)
| Line | waterLevel | lightLevel | Screen shows |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |
Copy this trace table onto paper and fill it in. Then check your values with the questions below.
| What the lab shows | True or false? |
|---|---|
| Line four uses the value waterLevel holds after line three. | ? |
| Line two changes waterLevel. | ? |
| DISPLAY changes the value of a variable. | ? |
| A trace table can catch a mistake that checking in your head missed. | ? |
Great lab work. Tomorrow you build expressions that do math with Beacon's readings.