|
I read in the book somewhere that an invariant needs to be true when the program enters the body of the loop AND if the program goes all the way to the end of the body, the invariant must also be true coming out. That means the only way to get out of the loop without the invariant being true is using a break, which we shouldn't use.All of this is true. So what do we do???We write the body of the loop very carefully so that the invariant is true at the end. That's the whole value of the invariant: it gives us knowledge about the state when the loop terminates. Mike O'D. |
to: