Why is a newline considered the start of a line if it appears at the end?

0
4
Asked By MistyHarbor42 On

If a newline character is usually placed after the text on a line, why is it called a "newline"? It seems like it ends the current line rather than starts the next one. Also, why do many text files conventionally end with a trailing newline when there is no more text afterward?

4 Answers

Answered By QuartzMango_8 On

The terminology comes from older printing equipment. A line-feed instruction moved the paper down, while a carriage return moved the print head back to the beginning of the line. Modern systems kept the idea even though text is usually displayed on a screen. That is also why some systems use LF (n), while others traditionally use CR followed by LF (rn).

CalmOrbit31 -

On a typewriter or printer, those were genuinely separate physical actions: move down to the next line and return horizontally to the start. Unix-like systems usually treat just LF as the logical line separator, while older Macintosh systems used CR alone.

Answered By PaperKite56 On

A newline can also be viewed as a boundary between two lines. When a parser encounters it, the text before it is one line and the text after it belongs to the next. The name emphasizes the line you move onto, not necessarily the line you just finished.

Answered By SilverPebble19 On

A trailing newline is useful because it marks the final line as complete. Many command-line tools and text-processing programs expect each complete line to end with a separator, so a file ending in a newline is treated consistently with all the other lines. Without it, the last line still exists, but it may be considered an unterminated line.

Answered By BrightCedar7 On

It helps to think of newline as an instruction rather than a character belonging to either line. It means “move to a new line” or “the next output should begin on a new line.” Since text is processed as a stream, placing it after a line’s content is a natural way to separate that line from the next one.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.