Volodymyr Bezuglyy
Volodymyr Bezuglyy

Reputation: 16825

Source.getLine - the line index, first line is 1

Why index starts from 1 not from 0? http://www.scala-lang.org/docu/files/api/scala/io/Source.html

Upvotes: 0

Views: 639

Answers (2)

Jesper
Jesper

Reputation: 206916

Because humans normally start counting at 1. Class Source in Scala is a representation of a source (text) file, and it's natural to start counting with the first line as number 1.

Upvotes: 0

atomice
atomice

Reputation: 3112

Line numbers traditionally start at 1. Wikipedia says:

The most common method of assigning numbers to lines is to assign every line a unique number, starting at 1 for the first line, and incrementing by 1 for each successive line.

The first high level programming language (Fortran) uses 1 for the index of the first element of an array. It was the C programming language that popularised using 0 for the first index.

Upvotes: 1

Related Questions