lesson

Updated 6 days ago Β· 2 views
What do you do when your program runs without crashing, but outputs the completely wrong answer?
Before modern debuggers existed, pioneers like Alan Turing verified programs by pencil and paper using a dry runβmanually executing each line of code step-by-step.
To keep track of changing data during a dry run without losing your place, we record state changes in a trace table.
πInteractive diagram
How do we construct these tables systematically without making careless record-keeping mistakes?
Anatomy of a Trace Table
A trace table has one column for each variable, one for condition checks (such as loop guards), and one for system output.
Every single iterationβone complete pass through a loopβrecords only the variables that actually change, moving down to a new row whenever a value updates.
πInteractive diagram
What does a complete dry run look like on real code with branching conditions?
Tracing a JavaScript Loop
Let's trace a standard JavaScript accumulator function that processes an array of numbers.
πInteractive diagram