The two senses of "invariant" are two of the most important concepts in
programming and
physics, respectively.
The programming sense is a predicate that stays the same as you go through a loop. See sorting example of invariant. Knowing your invariants is a good way to write bug free code.
In physics, invariants are closely tied to conservation properties. I.e. invariance under time and translation implies conservation of momentum.