Ad Space — Top Banner

?RETURN WITHOUT GOSUB ERROR

Commodore VIC-20

Severity: Minor

What Does This Error Mean?

?RETURN WITHOUT GOSUB ERROR means the program hit a RETURN statement without a matching GOSUB. The program flow accidentally fell into subroutine code, or a GOTO jumped into a subroutine. Add an END or STOP before your subroutines to prevent fall-through.

Affected Models

  • Commodore VIC-20
  • Commodore VIC-20CR
  • VICE emulator (VIC-20)

Common Causes

  • Program flow fell through into subroutine code without a GOSUB
  • Missing END or STOP before the subroutine section
  • GOTO jumped into the middle of a subroutine
  • Stack corruption from too many nested GOSUB calls

How to Fix It

  1. Add END before your subroutine section.

    If your main program ends at line 200 and subroutines start at line 500, add 200 END. Without END, BASIC runs from line 200 into line 500 and hits RETURN without a matching GOSUB.

  2. Never use GOTO to jump into a subroutine — always use GOSUB.

    GOSUB pushes a return address on the stack. GOTO does not. If you GOTO a subroutine, RETURN has nowhere to go back to.

  3. Make sure each subroutine ends with RETURN.

    If a subroutine is missing its RETURN, it may fall through into the next subroutine. That subroutine's RETURN then fails because it does not match any GOSUB.

Frequently Asked Questions

What is the difference between GOSUB and GOTO?

GOTO jumps to a line and never comes back. GOSUB jumps to a line but remembers where it came from, so RETURN can bring the program back.

How do I organise subroutines in VIC-20 BASIC?

Put all subroutines at the end of the program (high line numbers like 900+). Put END before the first subroutine. Call them with GOSUB from the main program.