Programming languages with 1-based array indexes

📄 Wiki page | 🕑 Last updated: Aug 29, 2022

Most mainstream programming languages today are using 0-based array indexes, i.e.:

0 => item1,
1 => item2,
2 => item3,
3 => item4,

But if you have worked with programming languages like Lua, Julia, or Mathematica/WolframLang, you'll know that's not always the case.

In human languages, when we're referring to a first item in a list, we use the term "first", not "zeroth" item, so 0-based indexing can be confusing to non-programmers. For that reason, historically, many languages used 1-based indexing, i.e.:

1 => item1,
2 => item2,
3 => item3,
4 => item4,

I worked with such languages in the past in the past, and in the practical sense, the advantage of this approach is that the last element is just array[count] instead of array[count -1] in 0-based indexing.

But on the other hand, there are a lot of cases where you have to add +1 all over the place (i.e. working with offsets or pointer arithmetics). Overall, I prefer 0-based access.

List of languages

There is a Wikipedia page on Array-based comparison of programming languages with a table of programming languages which we can use to extract only the list of languages with 1-based arrays:

ALGOL 68
APL
AWK
CFML
COBOL
Fortran
FoxPro
Julia
Lingo
Lua
Mathematica
MATLAB
PL/I
R
Ring
RPG
Sass
Smalltalk[16]
Wolfram Language
XPath/XQuery 

We could probably remove the XPath/XQuery and Sass from the list as they are not really programming languages, and there were some variants of BASIC with 1-based indexing.

Updated list:

ALGOL 68
APL
AWK
BASIC (some variants)
CFML
COBOL
Fortran
FoxPro
Julia
Lingo
Lua
Mathematica
MATLAB
PL/I
R
Ring
RPG
Smalltalk[16]
Wolfram Language

For the sake of completeness, here's also the other part of the list (0-based):

BASIC
C
C#
C++[16]
Ch
Cobra
Common Lisp
D
F#
FreeBASIC
Go
Hack
Haskell
IDL
ISLISP
J
Java[16]
JavaScript
Nim
Oberon
Oberon-2
Objective-C[16]
OCaml
Perl
PHP
Python
Raku
Ruby
Rust
S-Lang
Scala
Scheme
Swift
Visual Basic
Visual Basic .NET
Windows PowerShell
Xojo 

Ask me anything / Suggestions

If you have any suggestions or questions (related to this or any other topic), feel free to contact me. ℹī¸


If you find this site useful in any way, please consider supporting it.