Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M4134

Fencepost Error

Fencepost Error
StructureHigh supportLogic
Included
account_tree

Updated 2026-07-30

Loading revision record…

Summary

An off-by-one error (OBOE) is an error that occurs when counting, due to incorrect boundary condition judgment, resulting in a count that is one more or one less than the correct value. It typically refers to a programming error where a loop iterates one time too many or one time too few, and is a type of logic error. For example, a programmer might use 'less than' instead of 'less than or equal to' in a loop comparison, or fail to account for the fact that a sequence starts at 0 rather than 1 (as is the case for array indices in many programming languages). This error also occurs in mathematics.

Definition

If you want to build a 100-meter fence and place a post every 10 meters, you need 11 posts, not 10. This is the 'off-by-one error'. Scaffold use: boundary calculation. When doing project planning, budgeting, or scheduling, always be wary of that '+1' or '-1' boundary. The start and end nodes are often the overlooked cost centers.

How to use

Boundary calculation. When doing project planning, budgeting, or scheduling, always be wary of that '+1' or '-1' boundary. The start and end nodes are often the overlooked cost centers.

Mechanism

When dividing an interval into segments, errors often occur because the number of 'segments' and the number of 'interval points (fence posts)' differ by one. n segments of fence have n+1 posts, and n intervals cover n+1 endpoints.

Practice

In progress 0/3

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

Cases

  • Calculating whether a year has 52 or 53 weeks, loop boundaries running one iteration too many or too few, or incorrectly calculating the number of pages when paginating with 10 items per page.

Common pitfalls

  • Assuming the number of segments equals the number of points; mixing 0-based and 1-based indexing; ignoring the attribution of the first and last endpoints.
Sources

Source support: Explicit

References currently contain only Wikipedia links; primary sources still need review.

  • link
    zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E5%B7%AE%E4%B8%80%E9%94%99%E8%AF%AFZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS