Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exit Sub from inner loop?
#6
Here's a small test I've just run, which runs a snippet that calls a sub 10000 times, and exits early each time:
Code: (Select All)
Screen 9
For runs = 1 To 100000 '                            run the prog 10000 imes
    Numbers:
    For num = 1 To 10
        Print num; '                               print numbers 1 to 10
    Next
    letters '                                      now call the letters sub
    Print
    Print "Run #"; runs; "finished": Print '      show how many runs completed
Next
Print: Print "The final run should yield the same result as the first:"
Print " 1  2  3  4  5  6  7  8  9  10 ABCDEFGHIJ"
Sub letters
    letrnum = 0
    While letrnum < 26 '                           repeat this loop 26 times
        letr$ = Chr$(letrnum + 65) '
        If letrnum = 10 Then Exit Sub '            Bail out early, after j
        Print letr$; '                             show letter A, then B etc until Z
        letrnum = letrnum + 1 '                    next letter
    Wend
    _Delay .1
End Sub

There was no change in the output, so I assume there was no corruption caused by the early exit. Is this a reasonable assumption?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
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: 1 Guest(s)