Using a Loop Invariant at Exit

An invariant describes maintained facts. The loop's exit condition says which facts about remaining work hold when it finishes.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Trace a sum
  2. Check termination separately

Trace a sum

If the accumulator equals the sum of the first i entries and exit occurs at i=n, then the accumulator equals the sum of all n. See preservation of a step.

Check termination separately

An invariant can hold even during an infinite run. Establish that execution reaches the required boundary if the contract promises a result. Termination measures provide one technique.[1]

References

  1. Benjamin C. Pierce et al., Software Foundations ↩