Exit Sub from inner loop?
#7
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.  Wink
Reply


Messages In This Thread
Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 09:32 AM
RE: Exit Sub from inner loop? - by SMcNeill - 02-02-2023, 09:43 AM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 10:39 AM
RE: Exit Sub from inner loop? - by OldMoses - 02-02-2023, 04:10 PM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 11:09 PM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 11:48 PM
RE: Exit Sub from inner loop? - by SMcNeill - 02-03-2023, 12:04 AM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-03-2023, 12:56 AM
RE: Exit Sub from inner loop? - by SMcNeill - 02-03-2023, 02:13 AM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-03-2023, 02:40 AM



Users browsing this thread: 4 Guest(s)