i=0; found=0;
while (i<n && !found) { if (a[i]==value) found=1; i=i+1; } | The loop is designed so that if found is false, all elements of the array
before position i have been searched, and are definitely not equal to value. In other words, if found is true
a[i] must= value, if found is false then
for any x<i, a[x]!=value, giving: INV = (found && a[i]=V) || (!found && x<i => a[x]!=V) |
i=0; s=0;
while (i<10) { s=s+a[i]; i=i+1; } | The loop is designed so that i represents how far through
the calculation we are, and s is always correct so far (meaning s is the result of adding up the first i
elements), giving: INV = s=sum(a,0,i-1) (the first i elements are a[0], a[1], ..., a[i-1], not including a[i]) |
wp(preloop; WHILE cond DO body, {Q}) | = | wp(preloop, {INV}) |
&& | {cond && INV} => wp(body,INV) | |
&& | {cond && wp(body,{VAR=x})} => {VAR>x} | |
&& | {VAR<=0} => {!cond} | |
&& | {INV && !cond} => {Q} |