This program prints every character in the character set by iterating through all 256 character codes (0–255) using CHR$ and displaying each one consecutively on screen. The loop is built with a simple counter variable A, a PRINT with a semicolon suppressor to keep output continuous, and an IF/GOTO construct to repeat. The STOP at line 50 halts execution after all characters have been displayed. The SAVE line includes an inverse-video digit in the filename, and a RUN statement follows to allow immediate re-execution after loading.
Program Analysis
Program Structure
The program is a minimal character set display utility. It uses a linear flow across just five active lines:
10— Initialises counterAto 0.20— Prints the character corresponding toAwith a trailing semicolon to suppress newlines and keep output continuous.30— IncrementsAby 1.40— Tests whetherA < 256; if so, loops back to line20.50— Halts execution withSTOPonce all 256 codes have been printed.
Lines 60 and 70 are utility lines for saving and re-running the program and are not part of the display logic.
Loop Mechanics
The loop iterates through values 0–255 inclusive. The condition A < 256 at line 40 means the loop body at line 20 executes for every value of A from 0 to 255, giving exactly 256 iterations. After A reaches 255, it is incremented to 256 at line 30, the condition at line 40 fails, and execution falls through to STOP.
Key BASIC Idioms
- Semicolon in PRINT:
PRINT CHR$ A;suppresses the automatic newline, so all 256 characters appear as a continuous stream filling the screen row by row. - IF/GOTO loop: A classic counted loop pattern using a plain variable and a conditional branch, equivalent to a
FOR…NEXTbut slightly more explicit about the termination condition. - CHR$: Converts an integer code to its corresponding display character, making this an exhaustive visual index of the entire character ROM.
Character Coverage
Codes 0–31 on Sinclair machines are control characters (space, cursor movements, etc.) and will produce non-printing or screen-effect results rather than visible glyphs. Codes 32–127 cover the standard printable ASCII-like set. Codes 128–143 are block graphics, 144–164 are UDG slots (displaying default patterns if unprogrammed), and 165 onwards includes the keyword tokens. The output therefore gives a live map of all these regions at once.
Notable Techniques and Observations
- Using
A < 256rather thanA <> 256orA <= 255is safe here becauseAis incremented by exactly 1 each iteration and cannot skip the boundary value. - A
FOR A=0 TO 255 : PRINT CHR$ A; : NEXT Aconstruct would have been functionally equivalent and slightly more idiomatic, but the IF/GOTO approach works correctly and was common in early listings. - No
CLSprecedes the loop, so any previous screen content remains until overwritten by the printed characters. - The
REMat line1serves only as a title label (“CHARACTERS”) and has no effect on execution.
Content
Source Code
1 REM "CHARACTERS"
10 LET A=0
20 PRINT CHR$ A;
30 LET A=A+1
40 IF A<256 THEN GOTO 20
50 STOP
60 SAVE "1017%4"
70 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
