Another algorithm -- same problem
// Store 1 + 2 + 3 + 4 in s
Use invariant s= 0 + 1 + 2 + � + i.
To make it true, use initialization: s= 0; i= 0;
When will s = 1+2+3+4 be true? When i=4.
Body of loop: Make �progress� by increasing i and changing s to maintain the invariant:
// Invariant: s = 1+2+3+4