๐Ÿ“˜

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.

๐Ÿ”— Related concepts

โ† Whole glossary