Invariant
Something that stays true every time around a loop.
๐ In simple words
Something that stays true every time around a loop.
๐ Technical definition
A condition that holds before and after every iteration of a loop, used to reason about an algorithm's correctness.
Pseudocode example
1SET TOTAL = 02FOR I = 1 TO N3 SET TOTAL = TOTAL + I // TOTAL = 1 + โฆ + I4END FOR
๐ Real-world analogy
A seesaw kept balanced: whatever you add to one side, you match on the other.