Skip to main content
AP CSP course

F11 · Topic 3.8

Loop termination detective

Follow a bounded trace of a decrementing counter and distinguish a reached stopping condition from an observation limit.

1. Predict first

Start 10, subtract 3 each iteration, stop when counter=0. Predict the first five values after updates and explain the risk.

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 110Waiting
  2. Input 23Waiting
  3. Input 3at-mostWaiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Compare equal and at-most with start 10 and decrement 3, then try start 0.

2. Build your procedure

Write a safer loop that stops when the counter is at most 0. Test a starting value already satisfying the condition, an exact multiple and a value that crosses 0.

Use AP CSP pseudocode, a language you know, or precise plain language. Your code is not executed here. Use the classroom assignment to save your response.

3. Check boundaries

Public worked tests for the fixed model
InputExpectedWhy this case
start 10,step 3,equalDoes not reach 0 within 50 updatesThe supplied tool reports a bounded observation.
start 10,step 3,at-mostEnds-2 after 4 updatesCrossing the boundary still stops.
start 0,step 3,at-mostEnds 0 with 0 updatesCondition is initially true.

4. Explain and reflect

Why does the tool’s 50-step cap not decide the halting behaviour of arbitrary programmes?

Model limits: At most 50 updates of one fixed integer model. The equality case can be reasoned about mathematically, but the tool does not claim to decide general termination.

Teacher guidance and scoring