computing, a line number is a method used to specify a particular sequence of characters in a text file. 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.
In the C
programming languagethe line number of a source codeline is one greater than the number of new-linecharacters read or introduced up to that point. [cite web|url=http://c0x.coding-guidelines.com/6.10.4.html|title=6.10.4 Line control|date=2008-01-30|accessdate=2008-07-03|author=]
Line numbers were a required element of
syntaxin some older programming languagessuch as GW-BASIC.cite web|url=http://support.microsoft.com/kb/73084|title=Differences Between GW-BASIC and QBasic|date=2003-05-12|accessdate=2008-06-28|author=] The primary reason for this is that most operating systemsat the time lacked interactive text editors; since the programmer's interface was usually limited to a line editor, line numbers provided a mechanism by which specific lines in the source codecould be referenced for editing, and by which the programmer could insert a new line at a specific point. Line numbers also provided a convenient means of distinguishing between code to be entered into the program and commands to be executed immediately when entered by the user (which do not have line numbers).
Largely due to the prevalence of interactive text editing in modern
operating systems, line numbers are not a feature of most programming languages.
Line numbers and style
It was a matter of
programming style, if not outright necessity, in these languages to leave gaps between successive line numbers—i.e., a programmer would use the sequence (10, 20, 30, …) rather than (1, 2, 3, …). This permitted the programmer to insert a line of codeat a later time. For example, if a line of code between lines 20 and 30 was left out, the programmer might insert the forgotten line at line number 25. If no gaps were left in the numbering, the programmer would be required to renumber line 3 and all subsequent lines in order to insert the new line after line 2. Of course, if the programmer needed to insert more than nine additional lines, renumbering would be required even with the sparser numbering. Some BASICs had a RENUM command, which typically would go through the program (or a specified portion of it) reassigning line numbers in equal increments.
In a large program containing
subroutines, each subroutine would usually start at a line number sufficiently large to leave room for expansion of the main program (and previous subroutines). For example, subroutines might begin at lines 10000, 20000, 30000, etc.
Line numbers and GOTOs
In "unstructured" programming languages such as
BASICand Fortran, line numbers were used to specify the targets of branching statements. For example: GOTO-style branching is now widely considered by programmers to be poor programming style, as it tends to lead to the development of spaghetti code. (See Considered harmful, Structured programming.) Even in some later versions of BASIC that still mandated line numbers, the use of line number-controlled GOTOs was phased out whenever possible in favor of cleaner constructs such as the for loopand while loop.
Many modern languages (including C and
C++) include a version of the GOTO statement; however, in these languages the target of a GOTO is specified by a line labelinstead of a line number, and the use of GOTO is strongly discouraged by most programming style guides. The typically accepted use being when it is used to escape out of deep looping. For example:
This is much cleaner than the alternative that follows, which needs to have a much more widely scoped `done` variable.
Line numbers and syntax errors
If a programmer introduces a
syntax errorinto a program, the compiler(or interpreter) will inform the programmer that the attempt to compile (or execute) failed at the given line number. This simplifies the job of finding the error immensely for the programmer.
The use of line numbers to describe the location of errors remains standard in modern programming tools, even though line numbers are never required to be manually specified. It is a simple matter for a program to count the
newlines in a source fileand display an automatically generated line number as the location of the error. In IDEs such as Microsoft Visual Studio, in which the compiler is usually integrated with the text editor, the programmer can even double-clickon an error and be taken directly to the line containing that error.
Wikimedia Foundation. 2010.
Look at other dictionaries:
line number — eilutės numeris statusas T sritis informatika apibrėžtis Skaitinė eilutės ↑žymė dokumente. Eilutes gali numeruoti daugelis ↑rašyklių. Eilučių numeriai nėra dokumento dalis (jų nebūna dokumento faile), jie nespausdinami, tačiau gali būti rodomi… … Enciklopedinis kompiuterijos žodynas
Line number — Номер строки (на корректурном отпечатке) … Краткий толковый словарь по полиграфии
television line number — televizijos eilučių skaičius statusas T sritis radioelektronika atitikmenys: angl. television line number vok. Fernsehzeilenzahl, f rus. число строк телевизионного растра, n pranc. nombre des lignes en télévision, m … Radioelektronikos terminų žodynas
raster line number — kadro eilučių skaičius statusas T sritis radioelektronika atitikmenys: angl. raster line number vok. Rasterlinienzone, f rus. число строк в кадре, n pranc. nombre des lignes de trame, m … Radioelektronikos terminų žodynas
Trolly Line Number 9 Trail — The Historical Ellicott City/Baltimore Trolly Line #9 Trail is a convert|1.25|mi|km|1|sing=on trail in western Baltimore County, Maryland. It begins at the west end of Edmonson Avenue and extends from Catonsville through Oella to Main Street,… … Wikipedia
collection coordination facility line number — An arbitrary number assigned to contingency intelligence reconnaissance objectives by the Defense Intelligence Agency collection coordination facility to facilitate all source collection … Military dictionary
unit line number — A seven character alphanumeric code that describes a unique increment of a unit deployment, i.e., advance party, main body, equipment by sea and air, reception team, or trail party, in a Joint Operation Planning and Execution System time phased… … Military dictionary
Screen line number — Линиатура растра (число линий на сантиметр); Линиатура растра … Краткий толковый словарь по полиграфии
Line 1 (Budapest Metro) — Line number Line 1 ( Yellow metro ) Technical Line length 4.4 km Track gauge 1435 mm … Wikipedia
Number line — For other uses, see Number line (disambiguation). In basic mathematics, a number line is a picture of a straight line on which every point is assumed to correspond to a real number and every real number to a point. Often the integers are shown … Wikipedia