Solution (source code)

= Solution

A <loop invariant> is a property of the <program state> that holds whenever control reaches the loop's condition, including the final failed test. Its main purpose is proving <partial correctness>: establish it initially, prove one guarded iteration preserves it, then combine it with the negated condition to obtain the <postcondition>. A separate <loop variant> or another progress argument proves <algorithm termination> and hence <total correctness>.