?NF ERROR
Dragon Data Dragon 32/64
Severity: MinorWhat Does This Error Mean?
?NF ERROR means NEXT Without FOR — the Dragon encountered a NEXT statement but there is no matching FOR loop above it. This is usually caused by a missing FOR line, a misspelled variable name, or a GOTO that skips over the FOR.
Affected Models
- Dragon 32
- Dragon 64
- Dragon 200E
- XRoar emulator
Common Causes
- NEXT statement present but the FOR line was deleted or never written
- NEXT uses a different variable name than the FOR (e.g. FOR I but NEXT J)
- A GOTO or GOSUB jumps into the middle of a loop, bypassing the FOR
- Nested loops with mismatched variables
How to Fix It
-
Type LIST and locate both the FOR and NEXT statements.
Every NEXT must have exactly one FOR above it that uses the same variable. For example: FOR I=1 TO 10 must match NEXT I (or just NEXT).
-
Check that the variable name matches in FOR and NEXT.
FOR I = 1 TO 10 ... NEXT J will cause ?NF ERROR because I and J are different variables. Change NEXT J to NEXT I.
-
Check for any GOTO statements that jump inside the loop.
If a GOTO sends execution to a line number that is inside a loop (after the FOR but before the NEXT), the FOR initialisation never runs. Re-structure the code so all jumps enter loops from the FOR line.
-
Verify nested loops are properly ordered.
Nested loops must close in the reverse order they open. Correct: FOR I / FOR J / NEXT J / NEXT I. Wrong: FOR I / FOR J / NEXT I / NEXT J — this causes ?NF ERROR.
Frequently Asked Questions
Can I use NEXT without a variable name on the Dragon?
Yes. In Dragon BASIC, NEXT without a variable name closes the innermost FOR loop. However, naming the variable (NEXT I) makes code easier to debug and is recommended.
Does ?NF ERROR always appear at the NEXT line?
Yes. The Dragon reports the error at the line where the NEXT is encountered without a matching FOR. That line number is your starting point for debugging.