Docs

Pseudocode reference

Trace tables and dry runs

Track how variables change, pass by pass, to catch logic errors before the examiner does.

updated November 2, 2026

Why dry-run a program

A program can compile and still give the wrong answer. A dry run means following the program by hand with sample values and writing down each variable after it changes. In an exam, a quick trace catches most logic mistakes.

Trace a factorial loop

This program works out N factorial. Give each changing variable its own column and add a row for every pass of the loop.

Pseudocode
DECLARE N : INTEGER
DECLARE Fact : INTEGER
DECLARE I : INTEGER

INPUT N
Fact <- 1
FOR I <- 1 TO N
    Fact <- Fact * I
NEXT I
OUTPUT Fact
Trace with N = 5
IFact beforeFact after Fact <- Fact * I
111
212
326
4624
524120
Step 1 / 5
The expected output is 120.

When the trace and the output disagree

Run the program with the same input you traced. If the output is different, check the loop bounds and the starting values first: starting Fact at 0, or looping from 0, are the usual causes.

On a desktop or laptop, flowchart mode replays the run block by block, which lets you compare each step with your table.