More About the PRINT Command
Other than just printing numerics and strings, the PRINT Command has a few other features. The following are a few of the extra features.
Printing a Blank Line
If you want to print a blank line all you need to do is use the PRINT Command by itself with nothing following it. For example, the following code
print "Next Four Leap Years:"
print
print 2004
print 2008
print 2012
print 2016
will display a run window that looks like this:
With a blank line added to our code the output screen has a bit more readability than if it was left out. It is a good idea to use blank print statements whenever they will help the user read the information on the screen.
Joining Multiple PRINT Statements
You can join multiple PRINT statements by using the semi-colon. Print statements can be on separate lines as in the following example:
print "Hello";
print "World"
Or on the same line using only one PRINT statement:
print "Hello"; "World"
Both of the above examples produce the exact same results in the run window:
Notice that there is a slight problem with our code above. If we were expecting a space between the two words we need to add it in. Because a space is a character it needs to be added inside of the double quotes. By placing it either at the end of "Hello" or at the beginning of "World" a space will be included in our output window. Therefore, the code above could be rewritten as:
print "Hello ";
print "World"
Or
print "Hello "; "World"
In either case, our run will now look like this:
Combining Numerics and Strings in a PRINT Statement
One of the more useful uses of combining PRINT statements is the ability to mix strings and numerics together. For example, the following code:
Produces the following run:
Notice that we needed to add two spaces in our Liberty BASIC code to get the appropriate spacing in our run.
A slight problem occurs when trying to print two numerics to the screen beside each other. For example, if our code looked like this:
print 512; 318
Our output would look like:
512318
which is not what we want.
The solution to this problem is to add a string containing only a space in between the two numbers:
print 512; " "; 318
This will now produce:
512 318