EWD831 by E.W. Dijkstra, 1982.

When dealing with a sequence of length N, the elements of which we wish to distinguish by subscript, the next vexing question is what subscript value to assign to its starting element. Adhering to convention a) yields, when starting with subscript 1, the subscript range 1 ≤ i < N+1; starting with 0, however, gives the nicer range 0 ≤ i < N. So let us let our ordinals start at zero: an element's ordinal (subscript) equals the number of elements preceding it in the sequence. And the moral of the story is that we had better regard â€”after all those centuries!â€” zero as a most natural number.

**Remark** Many programming languages have been designed without due attention to this detail. In FORTRAN subscripts always start at 1; in ALGOL 60 and in PASCAL, convention c) has been adopted; the more recent SASL has fallen back on the FORTRAN convention: a sequence in SASL is at the same time a function on the positive integers. Pity! (End of Remark.)

What's the modern trend for indexing from zero vs. indexing from one? And for specifying ranges ("from 5 to 8", `5 ≤ N < 9`

, "four elements starting from 5")? Why?

## Recent comments

38 min 25 sec ago

1 hour 48 min ago

2 hours 3 min ago

2 hours 32 min ago

2 hours 59 min ago

3 hours 35 min ago

5 hours 11 min ago

5 hours 20 min ago

5 hours 21 min ago

5 hours 46 min ago