In computer science, a loop invariant is a property of a program loop that is true before each iteration. It is a logical assertion, sometimes checked within the code by an assertion call. Knowing its invariant is essential in understanding the effect of a loop.
What is meant by loop invariants of an algorithm?
A loop invariant is a condition [among program variables] that is necessarily true immediately before and immediately after each iteration of a loop. ... By itself, a loop invariant doesn't do much. However, given an appropriate invariant, it can be used to help prove the correctness of an algorithm.
What are loop invariants used for?
A loop Invariant can help in the design of iterative algorithms when considered an assertion that expresses important relationships among the variables that must be true at the start of every iteration and when the loop terminates. If this holds, the computation is on the road to effectiveness.