02-03-2023, 12:56 AM
(This post was last modified: 02-03-2023, 12:57 AM by PhilOfPerth.)
(02-03-2023, 12:04 AM)SMcNeill Wrote: Aye. As I mentioned previously, exiting from a SUB has zero bad repercussions.
Unless...
Code: (Select All)SUB foo
FOR i = 1 to 100
GOSUB fooGosub
NEXT
EXIT SUB
fooGosub:
PRINT i
IF i = 10 THEN EXIT SUB
RETURN
END SUB
Now, in the above, you're going to have issues eventually, and some folks would say "SEE?!! YOUR EXIT SUB EXPLODED THE PROGRAM!!!" -- which isn't *actually* the issue. The problem is you used an EXIT SUB to exit the sub WITHOUT returning from the GOSUB first. It's the GOSUB and the lost RETURN which is the true problem, and not the EXIT SUB, but it's still something to know to watch out for, if you ever use the routines in combination like that.
Sorry, Pete, I think I missed the point (yes, I'm a bit dense), but I ran your sub foo 10000 times (from a loop) and it executed as I expected - counted and displayed 1 to 10, then, from my loop, repeated this flawlessly and without throwing an error.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/