This program accepts a word from the user and displays it in four orientations: each letter printed downward one per line, each letter printed upward (reversed) one per line, the full word forward, and the full word spelled backward character by character. The string reversal uses the index expression `A$(L+1-J)` to walk from the last character to the first without storing a second string. A keypress wait using `INKEY$` in a tight loop at line 170 pauses the display before clearing the screen and looping back for a new word. The backward spelling uses a `STEP -1` loop with the semicolon suppressor to concatenate characters on one line without spaces.
Program Analysis
Program Structure
The program is a simple loop built around a single word input, with five distinct display phases before waiting for a keypress and restarting. The overall flow is:
- Prompt and accept a word into
A$(lines 10–20) - Clear screen and compute string length into
L(lines 30–40) - Print each character top-to-bottom (“DOWN”) and its mirror (“UP”) side by side (lines 50–80)
- Print the full word in one line (“FORWARD”) (lines 100–110)
- Print the word reversed character by character (“BACKWARD”) (lines 130–160)
- Wait for any keypress, clear screen, and restart (lines 170–190)
Key BASIC Idioms
Several idiomatic techniques appear in this short listing:
- Parallel column printing: Line 70 uses
PRINT A$(J),A$(L+1-J)with a comma to place both the forward and reversed character in adjacent print zones on the same line, giving a two-column display without any cursor positioning. - In-place reversal index: The expression
A$(L+1-J)maps indexJ(1 to L) to positions L down to 1, reversing the string without allocating a second variable. - Semicolon concatenation: Lines 150–160 use
PRINT A$(J);inside aSTEP -1loop to emit each character without a newline or space, building the backward word on a single output line. - Tight INKEY$ wait: Line 170 (
IF INKEY$="" THEN GOTO 170) spins until any key is pressed, a standard idiom for halting output for the user to read before continuing.
Variable Usage
| Variable | Purpose |
|---|---|
A$ | The input word entered by the user |
L | Length of A$, computed once at line 40 |
J | Loop counter used in both forward and reverse traversal |
Notable Techniques
The “DOWN” and “UP” columns are printed simultaneously in the same loop (lines 60–80), which is efficient: a single pass over the string produces both columns at once using the comma print separator for tab-stop alignment. This avoids needing two separate loops or storing a reversed copy of the string.
The “BACKWARD” section (lines 140–160) intentionally reuses the loop variable J from the earlier loop. Since the first loop leaves J=L+1 after termination, the second loop reinitialises it via FOR J=L TO 1 STEP -1, so there is no conflict.
Bugs and Anomalies
Lines 200 and 210 (SAVE and RUN) are utility lines intended for saving and restarting the program; they are not part of the program’s normal execution path, which terminates by jumping back to line 10 via GOTO 10 at line 190. If the user happens to reach line 200 (which cannot occur during normal running), RUN at line 210 would restart from line 10 anyway.
There is no guard against an empty input string. If the user presses ENTER without typing anything, L will be 0, the loops will not execute, and the program will print the section headers with no characters beneath them before waiting for a keypress — a minor but harmless edge case.
Content
Source Code
10 PRINT "GIVE ME A WORD"
20 INPUT A$
30 CLS
40 LET L=LEN A$
50 PRINT "DOWN:","UP:"
60 FOR J=1 TO L
70 PRINT A$(J),A$(L+1-J)
80 NEXT J
90 PRINT
100 PRINT "FORWARD:"
110 PRINT A$
120 PRINT
130 PRINT "BACKWARD:"
140 FOR J=L TO 1 STEP -1
150 PRINT A$(J);
160 NEXT J
170 IF INKEY$="" THEN GOTO 170
180 CLS
190 GOTO 10
200 SAVE "1003%7"
210 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

