Repair a shelf-label stopping defect
Scenario. A library prints one number for every shelf in a row, starting at 1.
Inputs. Number of Shelves, a non-negative whole number. For the main trace, use Number of Shelves = 3.
Rules and notation. The algorithm must output each label number from 1 through Number of Shelves once. An input of 0 produces no labels.
Before tracing, state the required output for 3 shelves: 1, 2, 3. Then trace the first 3 iterations of Listing 1 and inspect how the loop-control state changes.
Label Number after every output while the label number remains at or below the number of shelves.
Assumptions. Printing succeeds and does not change Number of Shelves.
Deliverable. Complete the checking sequence:
- State the expected output and trace the first 3 iterations for 3 shelves.
- Identify the loop-control state and explain how its update moves the state away from stopping.
- Repair only the faulty update. Retest 0, 1, and 3 shelves as zero-iteration, one-iteration, and multi-iteration cases.
- State a progress measure and explain why it reaches zero after the repair.
Success criteria. The trace identifies the update direction, the repair moves the loop-control state toward making the condition false, and each retest prints exactly the required labels before stopping. The termination explanation uses a quantity that decreases by 1 after each printed label.
The loop condition becomes false only when Label Number becomes greater than Number of Shelves.