Invariants
s = 0
i = 0
while i < n:
i = i + 1
s = s + iThis loop adds up . An invariant is a statement that is true before the loop and after every iteration.
Here the invariant is . A correctness proof has three parts: initialization, maintenance and termination.