๐ WAYPOINT LESSON
The state table
โญโญ intermediateโณ 10 min read๐ Lesson 85 of 256
One row per statement, one column per variable; right side first.
A state table is the exam's native language. One row per step, one column per variable โ never keep state in your head.
int a = 2;
int b = a * 3;
a = a + b;
b = a - b;
| step | statement | a | b |
| ---- | -------------- | - | - |
| 1 | a = 2 | 2 | โ |
| 2 | b = a * 3 | 2 | 6 |
| 3 | a = a + b | 8 | 6 |
| 4 | b = a - b | 8 | 2 |
Two discipline rules make tracing mechanical:
- Right side first, then assign. In step 3,
a + buses the old values (2 and 6) โabecomes 8, not 12. Assignment never re-reads its own left side. - New row per statement, even when nothing changes. Gaps are where mistakes hide. If a variable is untouched, copy its value down.
Swap puzzles like the one above appear on every exam: after
a = a + b; b = a - b;, b holds the old a (8 โ 6 = 2), and a third
statement a = a - b; would complete the swap. Tracing beats memorizing
the trick โ the table always tells you where you are.