larrybtoys
Full Member
 
Retired Part Time IT Professional
Posts: 154
|
Post by larrybtoys on May 27, 2023 16:32:02 GMT 1
Question for you GB32 gurus out there. I understand that it is not good programming practice however can GB32 handle exiting a For Next loop with a GoTo?
Example:
For T% = 1 to 100 If T% = 10 Goto Skip_All_Loops Endif Next T% ' For Y% = 1 to 100
If Y% = 20
Goto Skip_All_Loops Endif
Next T% ' Skip_All_Loops:
I know the proper way to do it buy I have a few older programs similar to this and would like to know if it will cause some sort of stack issues. TIA
|
|
|
Post by rogercabo on May 27, 2023 16:56:20 GMT 1
Yes sure sure you can do! As long as you Goto inside the procedure function or a sub.
And if you want to leave a Proc/Sub directly out of a Loop/or you can use Return. If done this since 30 years and never got any issues..
Proc Abc() Dim a, b, x, y While a > b If x = y Return EndIf Wend EndProc
|
|
|
Post by dragonjim on May 28, 2023 11:57:27 GMT 1
As Roger Cabo says, it is possible and GB32 can usually handle it, but it is not clean code and may cause an issue (extremely unlikely).
A cleaner alternative would be use Exit For, which cleanly ends the loops, as in the following two examples:
Dim T%, Y%
For T% = 1 To 100 If T% = 10 Exit For EndIf Next T% ' If T% = 101 For Y% = 1 To 100 If Y% = 20 Exit For EndIf Next Y% EndIf ' Skip_All_Loops: Debug T%,Y% Debug.Show
...or...
Dim T%, Y%
For T% = 1 To 100 If T% = 10 Exit For EndIf Next T% If T% = 10 GoTo Skip_All_Loops ' For Y% = 1 To 100 If Y% = 20 Exit For EndIf Next Y% ' Skip_All_Loops: Debug T%,Y% Debug.Show
|
|
|
Post by rogercabo on May 29, 2023 15:48:29 GMT 1
You can also use Exit Sub, Exit Proc, if you like to go out of the Proc/Sub directly.
|
|