---
title: "Tracing a Program by Hand"
description: "Following code line by line with a table of the variables, to say what it does and where it goes wrong. Errors that stop the program are found differently from errors that give a wrong answer."
canonical: https://lightmysky.com/learn/computing/tracing-a-program-by-hand-mt__rsnZ5Goow
source: https://lightmysky.com/learn/computing/tracing-a-program-by-hand-mt__rsnZ5Goow.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Tracing a Program by Hand

Following code line by line with a table of the variables, to say what it does and where it goes wrong. Errors that stop the program are found differently from errors that give a wrong answer.

Subject: Computing · Area: Programming · Ages 15 to 16
Page: https://lightmysky.com/learn/computing/tracing-a-program-by-hand-mt__rsnZ5Goow

## Ready when they can

- Fill in a trace table for a loop and give the final output
- Find the line responsible for a wrong result
- Tell a syntax error from a logic error by what the computer does with each

## Lesson: Think it through on paper

Tracing means walking code line by line with a table of each variable. You write down what every name holds as you go. At the end you can say what the program prints before you run it.

**Example.** A syntax error breaks the language rules, like a missing colon or a typo in a keyword. The computer cannot grasp your meaning, so it stops at once and points at the line. Fix it before the program can run at all.

A logic error is sneakier: the program runs start to finish with no complaints, yet the answer is wrong. The machine did exactly what you said, not what you meant. Trace by hand until the values drift off track.

**Tip.** Refuses to run plus a line number means a syntax slip. Runs fine but answers wrong means a logic slip. The symptom names the hunt.

**Recap.** Track every variable by hand to predict output, and let the symptom tell a syntax slip from a logic slip.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Reading a Program Someone Else Wrote](https://lightmysky.com/learn/computing/reading-a-program-someone-else-wrote-mt_VdxhuxjBSn)

## Opens up

- [Debugging as a Method: Reproduce, Isolate, Fix](https://lightmysky.com/learn/computing/debugging-as-a-method-reproduce-isolate-fix-mt_2JGE4ICRf6)
- [Linear Search](https://lightmysky.com/learn/computing/linear-search-mt_32LwZIhSiB)
- [Loop Invariants and Proving an Algorithm Correct](https://lightmysky.com/learn/computing/loop-invariants-and-proving-an-algorithm-correct-mt_fWnstju2ns)
