Loop Invariant

Overview

A loop invariant P is a condition that holds before, during, and after each iteration of a loop (e.g. for or while). These "timings" correspond to the three necessary properties of an invariant:

Notice loop invariants mirror mathematical induction. Initialization is analogous to an inductive base case while iteration is analogous to the inductive step.

Powered by Forestry.md