gosub error

SYS 64738
User avatar
drpump
Member
Member
Posts: 7
Joined: Mon Aug 04, 2014 5:43 pm
Location: london
Contact:

gosub error

Post by drpump »

I've googled this but can only find results for visual basic. When i put in this...

Code: Select all

10 print "yeah"
20 gosub 30
30 print "yeahhh man"
40 return
50 print "blahh"
It comes up with the message "error: return without gosub". But there is a gosub.
Help?


MarcWalters
Member
Member
Posts: 55
Joined: Wed Jun 11, 2014 2:33 pm
Location: Lake Macquarie, NSW, Australia
Contact:

Re: gosub error

Post by MarcWalters »

A RETURN statement must be matched by a GOSUB. But with your program, the program continues on until it hits line 40 and gets confused. The subroutine at lines 30 and 40 needs to be isolated from your main code.

What is happening under the hood is that when a GOSUB is encountered the line position is temporarily stored and then, just like a GOTO, control jumps to the line indicated. The RETURN fetches the stored position and then continues from there.

Put your subroutine at the end of your program and precede it with an END statement, which will end the program before it gets to the subroutine.

Code: Select all

10 rem *** main program
20 print "yeah"
30 gosub 110
40 print "blahh"
50 end
90 :
100 rem *** subroutine
110 print "yeahhh man"
120 return
User avatar
drpump
Member
Member
Posts: 7
Joined: Mon Aug 04, 2014 5:43 pm
Location: london
Contact:

Re: gosub error

Post by drpump »

I get it now. Thanks.
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 1 guest