Liberty BASIC Community Forum
« Gosub within a Gosub example »

Welcome Guest. Please Login or Register.
Nov 17th, 2017, 1:27pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Gosub within a Gosub example  (Read 559 times)
michael
Guest
xx Gosub within a Gosub example
« Thread started on: Apr 14th, 2015, 11:06am »

Gosub [SUB1]
wait
end
[SUB1]
for x =1 to 10
if x=5 then Gosub [SUB2]
next x
print " this should print last "
Return
[SUB2]
for y=1 to 1000
next y
print " this should print first "
return

'Apparently GOTO cannot be used to exit the routine.
'But I have seen it used like this: ( clear previous program)

Gosub [SUB1]
wait
end

[SUB1]
a= int(rnd(1)*2) +1 ' pick a random number between 1 & 2
if a=1 then goto [SUB1] ' move up to [SUB1] because a=1
return


« Last Edit: Apr 14th, 2015, 11:32am by michael » User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Gosub within a Gosub example
« Reply #1 on: Apr 15th, 2015, 11:24am »

That's right. Any time you use GOSUB, it must have a RETURN statement at the end of the subroutine, and it must be executed.

This is the way BASIC and other programming languages work when it comes to GOSUB. Always RETURN.

You can have more than one RETURN statement (for example in the middle of a subroutine an IF THEN statement might cause a RETURN.

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls