Chapter five: Program output

Scan of page 33 Scan of page 34 Scan of page 35

Printing - more complex formats

Printing was introduced in Chapter two, but some points need to be made about formatting.

It is often convenient to print several items on the same line. To print the items immediately adjacent, the variables may be separated with semi-colons.


30 PRINT A; B; C; D

Numeric fields are preceded either by a space or a minus sign and followed by a space, so in this case if A = 54, B = 2, C= —374 and D = 21, the output will be:


Character strings do not have leading or trailing spaces, so a statement such as:


will be output as:




will be output as:


Data can be spaced across a page using a comma as a separator. The page is divided into fifteen-character zones and the comma causes each item to be printed at the beginning of a zone. To skip a zone, two commas may be used as a separator.



will be output as:




will be output as:


showing that a whole fifteen-character zone has been skipped. A print line may have a mixture of separators if some items need to be printed adjacent to each other and some need to be spaced across print zones.

Printed output may be located at a specific print position by using TAB in the PRINT statement



The number in brackets is the position where printing should start. A will be output at print position one followed by “MORE” starting at print position six.

If the statement PRINT appears alone on a line, a blank line is printed. This is useful in spacing output.

If a PRINT statement line ends with a comma or a semi-colon, the next PRINT statement in the program will print on the same line


10 LΕΤ Χ = 1
20 LET A$ = "ABC"
30 PRINT A$;
40 LΕΤ Χ = Χ + 1
50 IF X < 5 GOTO 30
60 END

will produce:


The system will assume that the line length is seventy two print positions so that if the number of characters to be printed exceeds this, the seventy third character will appear in the first print position on a new line. Similarly with a comma separator, the sixth element will appear on a new line, as five zones can begin on each line.

The maximum line length can be reset to a lower or higher number using the MARGIN statement.


40 MARGIN 25

will set the maximum line length to 25 print positions. If at any time during a session the maximum line length is altered, it will remain at the new setting throughout all program runs until it is explicitly changed.

Summary of print editing

“:” separator text printed adjacent, with numerics preceded by a space or a minus sign and followed by a space.
“,” separator text printed at the beginning of the next fifteen-character print zone.
ΤΑΒ(n) text printed from print position n.

The PRINT USING statement

This statement allows printed output to be formatted. Numerics are introduced by + or - (for sign suppression) and character strings by < to left-justify or > to right-justify. Integer fields are printed right-justified with non-significant zeros suppressed unless an @ sign appears after the + or -. The # sign reserves places for characters within the formatted list. An exponent field is introduced by ↑↑↑↑


10 FΟR I = 1 ΤΟ 4
20 READ A$, A
30 PRINT USING "THE COST OF A <##### = £+@#.##":A$, A
50 DATA COAT, 2500, WATCH, 17.50, RING, 47.80, PEN, 02.20
60 END

This program will insert the appropriate character string into the first part of the format, left-justified, and the amount with its decimal point and non-significant zeros suppressed into the second part. The result is as follows:

THE COST OF A COAT   = £+25.00
THE COST OF A WATCH  = £+17.50
THE COST OF A RING   = £+47.80
ΤΗΕ CΟSΤ ΟF A ΡΕΝ    = £+02.20

The print format in line 30 could have been assigned to a string variable as follows:

25 LET G$ = "THE COST OF A <##### = £+@#.##"

Program execution will halt if the variables to be entered do not match the format to which they have been assigned. Program output includes output to files, and MAT PRINT output, which are explained in Chapters six and seven respectively.