off-by-one error

A bug where a count or index is one too many or one too few, such as looping one step past the end.

In more detail

Zero-based indexing and ranges that exclude their end value make it easy to slip by one, for example writing < where <= was needed. Stating whether each bound is inclusive or exclusive prevents most such bugs. Testing the first, last and empty cases by hand catches the rest.

Related terms

Taught in

References

Certification courses