Home

onebased

One-based, or one-based indexing, is the convention of numbering elements of a sequence starting at 1. In this scheme the first element has index 1, the second has index 2, and so on. This contrasts with zero-based indexing, where the first element is at index 0 and the nth element at index n-1.

The term is common in mathematics and in various programming languages and tools that expose user-friendly

Advantages of one-based indexing include alignment with everyday counting and many mathematical formulas, which can reduce

Disadvantages arise when interfacing with systems that use zero-based indexing. Conversions between schemes can introduce subtle

In practice, one-based indexing remains prevalent in mathematical writing and in several high-level languages and tools.

See also: zero-based indexing, off-by-one error, arrays, MATLAB, R, Lua, Fortran, spreadsheets.

indexing.
Languages
such
as
Fortran,
MATLAB,
R,
Lua,
and
Mathematica
use
1-based
indexing
for
arrays
by
default.
Spreadsheets,
databases,
and
many
user
interfaces
also
use
1-based
counting
for
rows
and
often
for
columns,
making
the
first
data
row
or
column
appear
at
position
1.
off-by-one
errors
when
translating
theory
to
practice.
It
can
also
feel
more
intuitive
to
non-programmers
when
selecting
data
and
iterating
over
sequences.
bugs,
especially
in
mixed-language
environments
or
when
manipulating
memory
and
pointers
in
low-level
code.
In
performance-critical
software,
zero-based
indexing
is
common
because
it
can
simplify
certain
calculations
and
improve
efficiency.
Users
should
be
aware
of
the
indexing
convention
used
by
their
environment
to
avoid
off-by-one
errors
and
to
ensure
correct
data
access
and
interpretation.