1. What is a dry run?
A dry run is the process of executing code on paper, in your mind, or in a table without actually running it on a computer. You read each line, update the values of variables, check conditions, and record output.
A dry run means manually tracing a program step by step, updating variables, checking conditions, and predicting output exactly the way the computer would. It is one of the most important thinking tools in programming.
A dry run is the process of executing code on paper, in your mind, or in a table without actually running it on a computer. You read each line, update the values of variables, check conditions, and record output.
Use this method every time, especially for loops and conditions.
Do not begin tracing too early. First understand the purpose of the program and identify inputs, variables, conditions, and output statements.
Write down the variable names you need to track. Common examples
are i, sum, count,
max, flag, and output.
Follow the order of execution exactly. Computers do not skip around unless the code tells them to with a condition, loop, function call, or jump in logic.
Whenever a variable changes, immediately record its new value. Never assume you will remember it later.
For every if, while, or loop
condition, decide whether it is true or false at that moment.
Anything printed should be tracked in a separate output column so you do not confuse displayed values with stored variables.
A dry run table is the safest method.
| Step | Current line | Variables | Condition | Output |
|---|---|---|---|---|
| 1 | x = 5 |
x = 5 | - | - |
| 2 | y = x + 2 |
x = 5, y = 7 | - | - |
| 3 | print(y) |
x = 5, y = 7 | - | 7 |
sum, write the new value every
time.
a = 5 b = 3 c = a + b print(c)
| Step | a | b | c | Output |
|---|---|---|---|---|
| Start | 5 | 3 | - | - |
c = a + b |
5 | 3 | 8 | - |
print(c) |
5 | 3 | 8 | 8 |
x = 10
if x > 5:
print("Big")
else:
print("Small")
Dry run: start with x = 10. Check the
condition x > 5. It is
true, so the program prints
Big. The else block does not run.
sum = 0
for i in range(1, 4):
sum = sum + i
print(sum)
| Iteration | i | sum before | sum after |
|---|---|---|---|
| Start | - | - | 0 |
| 1 | 1 | 0 | 1 |
| 2 | 2 | 1 | 3 |
| 3 | 3 | 3 | 6 |
Final output: 6
x = 2 y = 3 x = x + y y = x - y print(x, y)
| Step | x | y |
|---|---|---|
| Start | 2 | 3 |
x = x + y |
5 | 3 |
y = x - y |
5 | 2 |
Final output: 5 2
x = 1
for i in range(3):
x = x * 2
print(x)
n = 5
fact = 1
for i in range(1, n + 1):
fact = fact * i
print(fact)
Type very simple Python-like code using assignments,
print(), and loops written as
for i in range(a, b) or for i in range(n).
Then step through execution.
Supported lines: assignments like x = 5,
x = x + 1, print(x), and simple loops
of the form for i in range(...): with one indented
line inside the loop body.
In programming interviews, candidates often fail not because they do not know syntax, but because they do not carefully trace logic. A calm dry run can reveal off-by-one errors, incorrect updates, and misunderstood conditions.
Dry runs are not a beginner-only technique. Strong programmers use them whenever logic becomes tricky. The better you dry run, the better you debug, explain, and design programs.