What a trace table is
A dry run means working through an algorithm by hand, line by line, without a computer.
A trace table records the dry run. It has one column for each variable, and one for the output.
Write a new value in a column only when that variable changes. Move to a new row when the loop goes round again.
?Why?A dry run lets you check an algorithm before it is coded. It also shows exactly where a logic error happens.
!Watch outDo not fill every cell. Cambridge mark schemes usually want a value only where it changes. Copying values down is not wrong but takes time and causes mistakes.
Worked dry run
This algorithm reads numbers until the user types -1. A value that only means 'stop' is called a rogue value.
Input data: 12, 7, 20, 9, -1. Follow each row of the table below and check you agree.
Then use the toy. Pick Counting (WHILE), a similar rogue-value loop, and press Step to run it one line at a time.
e.g.ExampleRow 1: the three variables start at 0.
Value 12: Total 0 + 12 = 12, Count 1. 12 > 0, so Highest = 12.
Value 7: Total 19, Count 2. 7 > 12 is false, so Highest stays 12.
Value 20: Total 39, Count 3. 20 > 12, so Highest = 20.
Value 9: Total 48, Count 4. 9 > 20 is false.
Value -1: the WHILE condition is false, so the loop ends.
Output: 48 / 4 = 12, then 20.
DECLARE Value : INTEGER
DECLARE Total : INTEGER
DECLARE Count : INTEGER
DECLARE Highest : INTEGER
Total ← 0
Count ← 0
Highest ← 0
INPUT Value
WHILE Value <> -1 DO
Total ← Total + Value
Count ← Count + 1
IF Value > Highest
THEN
Highest ← Value
ENDIF
INPUT Value
ENDWHILE
OUTPUT Total / Count, " ", Highesttotal = 0
count = 0
highest = 0
value = int(input())
while value != -1:
total = total + value
count = count + 1
if value > highest:
highest = value
value = int(input())
print(total / count, highest)!Watch outThe rogue value -1 is not added to the total. The loop checks the value before using it. That is why there is an `INPUT` before the loop and another at the end of it.
There is something to try for this step in the IGCSE library.