Variable Not Found
Sinclair ZX Spectrum
Severity: MinorWhat Does This Error Mean?
Variable Not Found (error code A) means the program referenced a FOR loop variable that was never started with a FOR statement. Usually a NEXT without a matching FOR.
Affected Models
- ZX Spectrum 16K
- ZX Spectrum 48K
- ZX Spectrum+
- ZX Spectrum 128K
- ZX Spectrum +2
- ZX Spectrum +3
Common Causes
- NEXT I used without a preceding FOR I = ...
- FOR loop variable used outside the loop
- Variable name typo (Spectrum variable names are case-sensitive in some dialects)
- Program jumped past the FOR statement using GOTO
How to Fix It
-
Check that every NEXT has a matching FOR.
Spectrum BASIC error A specifically refers to FOR loop variables. List your program (LIST command) and trace each NEXT back to its FOR.
-
Check you haven't jumped over the FOR with a GOTO.
If a GOTO or GOSUB skips the FOR statement, the variable is never initialised. Restructure the program so the FOR is always executed before its NEXT.
-
Check for typos in the loop variable name.
FOR loops on the Spectrum use single letters only (FOR I, FOR J, etc.). Mismatching the letter in NEXT causes error A.
Frequently Asked Questions
How are ZX Spectrum errors numbered?
The Spectrum uses letter codes (A through R) rather than numbers. Error A = Variable Not Found, B = Subscript Wrong, C = Nonsense in BASIC, etc. The error code appears at the bottom of the screen alongside the line number where the error occurred.