0

High level programming languages are made to be understandable to humans, but 0 is usually not accepted as a natural number in mathematics. I do not understand why all programming languages I have seen always start counting from 0, eg. int[0] = 1st element instead of int[1] = 1st element. I want to know whether there are any programming languages that support this? If not, why?

rtuner
  • 2,362
  • 3
  • 25
  • 37
  • Duplicate of (closed) http://stackoverflow.com/questions/1499749/list-of-1-indexed-programming-languages, should be closed for the same reason. – gabr Mar 13 '12 at 15:41
  • Also see http://programmers.stackexchange.com/q/110804/7043 for the why. There are plenty of good reasons. Besides, whether 0 is a natural number is *not* agreed upon. There's a reason for the `N \ {0}` (natural numbers except zero) notation. –  Mar 13 '12 at 17:46

2 Answers2

1

Not so many (considering the total number of programming languages)

ALGOL 68
APL
AWK
CFML
COBOL
Fortran
FoxPro
Informix
Julia
Lua
Mathematica
MATLAB
PL/I
Ring
RPG
Sass
Smalltalk
Wolfram Language
XPath/XQuery

You can do it in Perl

$[ = 1;  # set the base array index to 1

Erlang's tuples and lists index starting at 1.

Sources

Kas Elvirov
  • 7,394
  • 4
  • 40
  • 62
1

Yes, lots. Fortran for example.

And then there are languages which allow array elements to start indexing at almost any integer. Fortran for example.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161