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.

Listing 1: Proposed shelf-label algorithm that subtracts 1 from Label Number after every output while the label number remains at or below the number of shelves.
Input: Number of Shelves
Output: Shelf Label Numbers
Start
   Set Label Number to 1

   While Label Number <= Number of Shelves
      Output Label Number
      Set Label Number to Label Number - 1
   End While
End

Assumptions. Printing succeeds and does not change Number of Shelves.

Deliverable. Complete the checking sequence:

  1. State the expected output and trace the first 3 iterations for 3 shelves.
  2. Identify the loop-control state and explain how its update moves the state away from stopping.
  3. Repair only the faulty update. Retest 0, 1, and 3 shelves as zero-iteration, one-iteration, and multi-iteration cases.
  4. 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.