1 NEXT without FOR
Sinclair ZX Spectrum
Severity: MinorWhat Does This Error Mean?
Error 1 on the ZX Spectrum means BASIC encountered a NEXT statement without a matching FOR loop. This usually means the loop variable is wrong, program flow jumped into the middle of a loop, or the FOR statement was never executed. Check that every NEXT matches a corresponding FOR.
Affected Models
- Sinclair ZX Spectrum 48K
- Sinclair ZX Spectrum 128K
- Spectrum+
- Spectrum +2
- Spectrum +3
- ZX Spectrum Next
- Fuse emulator
Common Causes
- NEXT refers to a variable that has no matching FOR loop
- Program flow jumped into the loop body via GOTO without going through FOR
- FOR loop is inside an IF block that was skipped, but NEXT is outside it
- Variable name mismatch — FOR I but NEXT J
- Nested loops crossed — FOR I, FOR J, NEXT I, NEXT J instead of the correct order
How to Fix It
-
Check that the variable name in NEXT matches the one in FOR.
FOR I = 1 TO 10 must end with NEXT I, not NEXT J. A mismatched variable name means BASIC looks for a FOR J that does not exist.
-
Make sure no GOTO jumps into the middle of a loop.
If GOTO sends the program to a line between FOR and NEXT without going through FOR first, the NEXT has no matching FOR. Always enter loops through the FOR statement.
-
For nested loops, make sure they close in the correct order — last opened, first closed.
Correct: FOR I, FOR J, NEXT J, NEXT I. Incorrect: FOR I, FOR J, NEXT I, NEXT J — this crosses the loops and confuses BASIC.
-
Check that the FOR statement is not skipped by an IF condition.
If FOR is on a line that only executes conditionally (inside an IF), but NEXT always executes, you get this error when the condition is false. Move the FOR outside the IF, or make sure NEXT is also conditional.
Frequently Asked Questions
Can I use NEXT without specifying the variable name on the Spectrum?
No. Unlike some other BASIC dialects, Spectrum BASIC requires NEXT to include the variable name. You must write NEXT I, not just NEXT. Omitting the variable causes a syntax error.
How many nested FOR-NEXT loops can the ZX Spectrum handle?
The Spectrum can handle quite deep nesting, limited only by available memory. Each nested FOR uses about 18 bytes of stack space. In practice, 10-20 levels of nesting is fine for most programs.