Curriculum

Curriculum

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).

  1. 1Before the loop
  2. 2After pass 1
  3. 3After pass 2
  4. 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.

Reveal the explanation
  1. Before the loop

    5 papers remain. 0 passes completed.

  2. After pass 1

    2 graded, 3 remain.

  3. After pass 2

    2 graded, 1 remains.

  4. 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

A quiz scorer starts with papersLeft = 5 and grades up to 2 papers per pass while papersLeft > 0. How many passes appear in the trace table?
Show the answer and reasoning

Correct answer 3 passes

Pass 1 goes 5 -> 3, Pass 2 goes 3 -> 1, and Pass 3 goes 1 -> 0. After 3 passes, 0 > 0 is false.