Offbyone
Off-by-one error, commonly called an off-by-one bug, is a frequent programming flaw where a loop boundary or index targets one element too many or too few. It typically arises from confusion between inclusive and exclusive bounds or between zero-based and one-based indexing. The result is that code accesses an element outside the intended range, or misses the first or last element.
Causes and patterns include using <= where < is intended in loops, or using length as the last
Examples are common across languages. In C, for (i = 0; i <= n; i++) accesses n+1 elements,
Mitigation strategies include adopting half-open intervals (start inclusive, end exclusive), using language-provided iteration constructs, and writing
See also: zero-based indexing; inclusive-exclusive bounds; boundary testing.