Trace Tables

Computers can read and execute code but that is no guarentee that the code is correct. Humans have to be able to read and understand code without even pressing a key. When creating an algorithim to have to do a dry run of the code on paper to ensure that what you have designed will work when put onto a computer.

Dry runs can be done by using a trace table. Simply it is a list of all variables used in the code and how those variables change over the course of the code. Consider the trace table for the follwing code fragment -

  1. B = 40
  2. FOR (A = 1 TO 5)
  3. C = B + 1
  4. B = B -1
  5. NEXT
A
B
C
  40  
1 39 41
2 38 40
3 37 39
4 36 38
5 35 37

The last row shows the final result of the variables A, B and C. The trace table can be used to ensure that the values change the way they should. It is a way of debugging code without actually entering it on the computer.

The rules for creating a trace table are -