Syntax
Description
PRINT
is a sentence used to output information on the screen. The ZX Spectrum screen is divided in 24 rows (numbered
from 0 to 23), and 32 columns (numbered from 0 to 31). So it's composed of 24 x 32 = 96 cells. Cells are referred by
its coordinate (row, column), being (0, 0) the top-leftmost cell, and (23, 31) the bottom-rightmost one.
There's a hidden cursor on the screen that points to the coordinate where the next character will be printed. Each time something is printed, a carriage return is also printed and the screen cursor is advanced to the next line (row):
If you don't want this to happen, you can add a semicolon (;) at the end of the PRINT
sentence, and the next
printed expression will still be on the same line:
PRINT
ends with a semicolon to avoid carriage return. Executing a single PRINT
will just
advance the cursor to the next line.
NOTE: when the cursor reaches the end of the screen, it will scroll upwards all rows 1 position.
Let's prints numbers from 0 to 25 and see what happens:
CLS: REM Clears screeen and puts the cursor at the top-leftmost corner
FOR i = 0 TO 25
PRINT i
NEXT i
NOTE: When the screen is cleared with CLS, the cursor is set to its default position (0, 0), that is, the top-leftmost screen corner.
PRINT
can print everything that is a single expression (also called an item).
That is, strings (like in the previous example), numbers, variable values, and array elements
(it can not print an entire array; that's not a single
element but a collection):
For example:
Indeed, if you want to chain several expressions one after another you can chain them in a single PRINT sentence using semicolons:
Changing the print position
You can change the current cursor position using the AT modifier:
PRINT AT 5, 0; "This message starts at ROW 5"
PRINT AT 10, 10; "This message starts at ROW 10, COLUMN 10"
Again, you can chain all PRINT
items using semicolon:
Changing appearance
You can temporarily override the aspect of the items printed using them inline:
See the related commands section for further info.
Examples
REM Prints a letter in the 10th row of the screen moving from left to right
CLS
FOR i = 0 TO 31
PRINT AT 10, i; "A"
PAUSE 10
PRINT AT 10, i; " ": REM Erases the letter
NEXT i
Remarks
- This sentence is compatible with Sinclair BASIC but expands it, since it allows printing at rows 22 and 23 (all 24 rows are available to the programmer). Traditionally, Sinclair BASIC only allows to print at rows 0..21.
- You can use ITALIC and BOLD modifiers (not available in Sinclair BASIC)