Free practice · ordering · medium

Practice

Order a loop trace

Arrange the steps for tracing one iteration of a counter-and-total loop.

Repeated-state trace

A loop must make visible progress toward a defined stop

  1. InitializeSet deliberate starting state
  2. ReadTake the next item or state
  3. DecideEvaluate the loop condition
  4. UpdateChange counters and accumulators
  5. RecordWrite the reached state
  6. StopConfirm the stopping rule

Record the item, condition, counter, accumulator, and stopping decision on every pass to expose skipped, duplicated, or non-terminating work.

Arrange in the correct order
  1. 1. Check whether another item remains
  2. 2. Record counter and accumulator state
  3. 3. Apply only the updates in the selected path
  4. 4. Evaluate the iteration's condition
  5. 5. Read the next item