EZ Programing Demos

Slow motion, step by step, animated demonstrations of basic computer programing techniques

Links to topics:

Current topic:

Printing several times on one line

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.

 Slow  Medium  Fast 
Click 'Run' to go.

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:

At EZ Math Movie :

EZ Math Movie is a site that can help you experiment with and understand many topics in mathematics. Its main feature is an interactive animated (x, y) graph that you control with an actual programing language. There are many examples and tutorials, and EZ Math Movie is crossed referenced with both EZ Programing Demos and Zona Land Education.

 

Zona Land Education is a site with explanations and interactive diagrams covering many topics in physics and mathematics. Zona Land Education is cross referenced with EZ Math Movie, and it contains several animations that use EZ Math Movie's programing language.