Liberty BASIC Community Forum
« Gosub within a Gosub example »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 10:59am

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 621 times)
xx Gosub within a Gosub example
« Thread started on: Apr 14th, 2015, 11:06am »

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

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

Gosub [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

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


member is offline


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.

User IP Logged

author of Liberty BASIC
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