Invariants
The “General picture”, or “invariant” is a relation that shows how the values of the variables are related just before and just after each iteration. It gives the meaning of the variables before and after each iteration. It helps us understand what the loop is doing.
For each loop, write an invariant, which shows the state of affairs before and after each iteration. The invariant gives the meaning of the variables during execution of the loop.
The initialization “truthifies” the invariant (makes it true).
Each iteration “maintains” the invariant (keeps it true).
Condition is written so that when the loop terminates, the general picture helps us see that the desired answer has been obtained.