Explain Loop Invariants to me


I'm on a section in my book that talk about loop invariants, apparently are statements that you would write before a "while" statement to make sure the "while" statement is true,

however, i'm struggling to grasp the concept, which was presented imo, in a very convoluted way with only one example. No matter how many times i've re-read it, i still can't quite understand it enough to put it into practical use.

So can someone sort of lay out the context, example and maybe some reasons why you would use something like this? Any help is appreciated
Topic archived. No new replies allowed.