Suppose you have some loop and and integer k:
int k = 5;
for (int i = 0 ; i < N; i++)
{
//(*)
//do something
}
The loop invariant at (*) is: $\{ K=k\}$
Does that guarantee that $k$ doesn't change in between iterations? if not, is there any otherway to guarantee that?
constant
modifier that many imperative languages come with. If you want to be explicit in your Hoare logic about it, then you can reference the new updated value or the old value and indicate that they are the same. For example, in the Z formalism, you would writek = k'
which says updated valuek'
is identical to original valuek
. Another example would bek == \old(k)
if you were using Frama-C. $\endgroup$