F11 · Topic 3.8
Loop termination detective
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
- Input 110Waiting
- Input 23Waiting
- 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
| Input | Expected | Why this case |
|---|---|---|
| start 10,step 3,equal | Does not reach 0 within 50 updates | The supplied tool reports a bounded observation. |
| start 10,step 3,at-most | Ends-2 after 4 updates | Crossing the boundary still stops. |
| start 0,step 3,at-most | Ends 0 with 0 updates | Condition 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.