Click 'Run' to go.
Here we see what the term 'line' in the printLine command means.
In this demonstration the command printLine is executed three times in a row. When you run the program, be sure to take notice that each printLine command prints its text and then creates an empty new line. In this way each printLine command starts printing on its own new line, the new line left by the prior printLine command. Without these new lines all of the text for the entire program would be printed continuously on one line with no line breaks.
You may want to change the text in the printLine commands and watch the effect on the output.
The typewriter carriage return
The new line that printLine outputs works very much like a carriage return arm on an old-fashioned typewriter. It positions any subsequent printing down one text line and over at the left margin.
There is another way to print information. Be sure to see the article named 'Printing several times on one line' to see this other method.
A command like printLine does two things: First, it prints the text as one would expect. Second, it is said to print a 'new line'. Nothing appears on the printer when a new line is printed. However, if any more printing is done later, that printing will appear on the next line down.
As you will see, a computer language may contain a command that works like our command print, which is found in some of the following examples. The command print functions just like printLine, except it does not output a new line as its final step.
So, computer languages usually have the ability to print something and then move to a new line, or to print something and stay on the same line.
Sometimes printing a new line is called printing a 'carriage return', and sometimes it is even called printing a 'new line and carriage return'.
Here is a flowchart that shows how this program runs:
In an imaginary language, this is how this program might look:
printLine("First line of words"); printLine("Second line of words"); printLine("Third line of words");
Suggested next article:
This article is related to this demo: