Click 'Run' to go.
Now we will look at the print command. The print command works just like the printLine command except there is no new line generated as a final step.
So, if several print commands are executed in a row, since no new lines are created, all of the text from all of the print commands ends up on the same line.
The following demonstration will hopefully make all this clear.
Again, like in the article titled 'Printing words', note the quotes around the words in the print command. Understand that quotes are not used when variable values are printed, as shown in the article 'Printing the value of a variable'.
Take a careful look at the second print command that prints the word 'is'. Notice that the text for the word actually starts with a space. The text is spelled [space]-i-s. The next two print commands each have text starting with a space also. These starting spaces attached to words and phrases provide the spaces between the words that are seen in the final sentence.
Space characters placed before words or phrases are often called leading spaces.
Since you can change the text, experiment with removing some of these leading spaces and note the effect on the printed output.
Trailing spaces are spaces that follow words or phrases. Can you figure out a way to achieve the same original output with trailing spaces? Experiment and see if you are correct.
The command print outputs the text which it has been given and nothing more. It does not move the printer to the next line as the command printLine does.
A command like print is useful when you want to output several items one at a time, but you want all of the output to appear on one line.
Here's a flowchart for this program:
Imaginary computer language code could look like this:
print("This"); print(" is"); print(" all on"); print(" one line.");
Suggested next article:
This article is related to this demo: