exit nested loop

vaibhav

New member
Joined
Jan 19, 2007
Messages
1
Programming Experience
Beginner
help

i am the new to .nt and i have been started few day before ,
i have prb with exiting the inner for loop when nested together,
i want to be exit whole for loop statments than just one so plz help me
 
Use a boolean flag variable. Inside the inner loop:

If condition Then
flag = True
Exit For
End If

After exiting the inner loop:

Next
If flag = True Then
flag = False
Exit For

That will get you right out of the outer loop.
 
Depending on how you organize code there may be different solutions. For example if you run the nested loops in its own sub or function method it may be appropriate at some point in iteration to exit this method with Exit Sub statement or return a value with the Return statement. In a sub method the Return statement is actually equivalent to Exit Sub.
 
Back
Top