


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



s = s + a[i];
What is the ‘loop invariant’?
s is the sum of elements from a[1] to a[i] immediately before i is incremented!
-^ Let W be while B do S -^ condition for termination of the loopP
0 (not B) P^1
^ B and wp(S,P
)^0
^ wp(S, not B)
Pk
^ B and wp(S, P
)k-
wp(W, not B)
(k: k
)k docsity.com
a = 0;i = 0;while (i < N)
a = a + i++; Loop Invariant: a =
i