IT lexicon › Programming › Induction variable

Induction variable

Programming På svenska → Updated: 2026-11-05

A variable that changes by the same step on every loop iteration — and the thing a compiler must understand before it can optimize the loop at all.

The loop counter i is the basic induction variable. Derived ones are linear expressions in it, such as 4*i + base when indexing an int array. Once the compiler recognizes the pattern it can replace the multiplication with one addition per iteration (strength reduction), merge redundant counters, and compute the trip count up front — a prerequisite for both unrolling and vectorization.

LLVM devotes an entire analysis, scalar evolution (SCEV), to describing such values as recurrences. This is also one of the few places where C's undefined behaviour pays off: because signed overflow is UB, the compiler may assume an int i never wraps and widen it to 64 bits without checking.

← Back to the lexicon