Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exiting sub while inside a loop PhilOfPerth 5 525 12-05-2025, 09:40 AM
Last Post: PhilOfPerth
  Do Loop, Sleep and Mouse Button Dimster 5 599 09-06-2025, 12:57 PM
Last Post: Dimster
  Using modulo to loop through lists fistfullofnails 3 726 09-03-2025, 11:50 PM
Last Post: fistfullofnails
  What is wrong with this for/next loop Helium5793 6 1,164 04-15-2025, 05:11 PM
Last Post: Kernelpanic
  Question on ln in a for/next loop Dimster 13 2,251 09-13-2024, 11:07 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)