Practice question · Multiple choice
A loop invariant proof establishes that if the loop terminates, the answer is right. Why is termination a separate obligation, and how is it discharged?
Hints
- Write a loop that preserves a perfectly good invariant and never stops.
- Ask what quantity would have to change monotonically for the loop to be guaranteed to end.
Show the answer
B. Because an invariant can hold forever in a loop that never exits
Why
while true preserves any invariant you like, so partial correctness and termination are genuinely separate. A decreasing bounded measure, a variant, supplies the second, and it is the same shape as induction. Option 3 overstates the halting problem: no general procedure exists, and particular loops are proved routinely.
Practise Loop Invariants and Correctness Ideas
The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.