Link to home
Start Free TrialLog in
Avatar of NevSoFly
NevSoFly

asked on

How would I exit an outer for loop from within an inner for loop?

I have the following:

For a = 0 to 10
   For b = 0 to 10
      If (some condition) then
         'do something
      else
         exit outer loop (a) 'this is what I can't figure out how to do.
      End if
   Next b
Next a

How do I exit the outer For loop (a) from within For loop (b)?
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>Having to force exit from for loops indicates a bad program design

I would say that is only partially correct.  There are times when a for loop does make sense eg. iterating an array, and one may want to exit the for loop before the end of the array is reached.
What is certain is that a for loop could be written as a while loop BUT that might be the same code in effect - just requiring more lines of code to be written.