|HOW TO PRINT|
|Up to now we have used the PRINT statement as and when it was needed to print out headings and variables. In fact PRINT is a very versatile statement indeed.
The general form of the PRINT statement is
PRINT expression ch expression ch expression ch . . . and so on.
ch stands for control character and this can be , or ; or nothing at all (at the end of the statement only).
Expressions can be literal strings in quotes, e.g. "THIS IS A LITERAL STRING" or string variables such as A$
Alternatively they can be integer variables or arithmetic expressions, e.g. A2 or B*2/C
The object of using control characters is to be able to control the spacing of the line to be printed. We've already come across the use of ; in PRINT statements. The program
10 LET X=4
THE ANSWER IS4UNITS
The semi-colon (;) makes the computer print out the expressions without any spaces between them. If you want spaces you have to include then in the literal strings to be printed.
The comma (,) is used as a tab. Each display line of 32 characters on the screen is divided into 4 fields each of which is 8 characters in length. Each time the computer comes across a comma in a PRINT statement, it starts printing the next expression at the beginning of the next available field.
The effect of this is to provide a display on the screen in 4 columns. If a string variable or literal string is more than 7 characters long and is followed by a comma the computer uses two or more fields in which to print the string and starts the next expression at the beginning of the third field.
You can add extra commas to skip fields:
PRINT "FIELD 1”, "FIELD 2", "FIELD 3"
would produce the output
FIELD 1 FIELD 2 FIELD 3 but
PRINT "THIS IS A FIELD”,,”FIELD1”,"FIELD2" would produce
THIS IS A FIELD FIELD 1
The computer used 2 fields for the first string, skipped a field and then continued. It runs out of fields on the first line and has to continue in the first field of the second line.
There is no limit to the number of fields you may skip using commas, (Unless you run out of display area, of course.)
If you use a control character right at the end of a PRINT statement the next PRINT statement will obey the control character. For instance
10 LET X=4
20 PRINT "THE ANSWER IS ";
30 PRINT X
will produce the output
THE ANSWER IS 4
If no control character occurs at the end of a line the next PRINT statement will start printing on a new line.
The best way of finding out about PRINT is to experiment with it.