Correctness, Invariants & Design


Answer & solution
Answer: i is even at each loop test (no official key was published)
The outer test establishes evenness before the first loop test. Let j be the quotient after the division in an iteration. If j is odd, j−1 is even; if j is even, j−2 is even. Thus either branch reestablishes the invariant regardless of the parity produced by division. Nonnegativity is the loop guard, not an invariant after the body: for i=0 the body produces −2 and terminates. An even negative initial value skips the loop altogether. The invariant states a preserved property, not a complete description of all reachable values.