Count Exact Passes with a Loop Trace Table
Scenario
A classroom quiz scorer grades papers in batches of 2 while papersLeft > 0. Each pass reduces papersLeft by 2 (clamped at 0 if 1 paper remained).
- 1Before the loop
- 2After pass 1
- 3After pass 2
- 4After pass 3
Try it yourself
Before writing the table, predict how many passes it takes to finish 5 quiz papers when grading up to 2 per pass.
| Case | State after the step |
|---|---|
| Before the loop | — |
| After pass 1 | — |
| After pass 2 | — |
| After pass 3 | — |
Reveal the explanation
- Before the loop
5 papers remain. 0 passes completed.
- After pass 1
2 graded, 3 remain.
- After pass 2
2 graded, 1 remains.
- After pass 3
1 graded, 0 remain. The loop ends after 3 passes.
Guessing total passes by division fails on remainders or off-by-one boundaries. Writing one row per pass makes every check and state change visible so your count is exact.
Download shared test cases
Your turn
Build a loop trace table for grading papersLeft = 7 with batchSize = 3 while papersLeft > 0. List pass number, papersLeft at start of pass, and papersLeft after pass.
Common mistake Using integer division 7 / 3 = 2 and forgetting the final pass needed for the remaining 1 paper.
Check your work
A 3-row trace table: Pass 1 (7 -> 4), Pass 2 (4 -> 1), Pass 3 (1 -> 0), then stop at 0 > 0 false.
Quick check
This browser could not save your progress. Changes last until you leave the page.