Computer Science I / Loop Invariants and Correctness Ideas
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
  1. Write a loop that preserves a perfectly good invariant and never stops.
  2. 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.

Read the lesson: Loop Invariants and Correctness Ideas →

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.

More questions on Loop Invariants and Correctness Ideas