Using for in nested loops

O

Oded Kovach

Hello there

I have For on vb.

When i want to leave it before i'm using Exit for

Now i have nasted loops:
For i = 1 to 10
For j = 1 to 10

If i'm inside the j for what i need to do to go out from the j for and what
should i do for exiting the I for?

any help would be useful
 
A

Allen Browne

Set a flag:

Dim bFound as Boolean
Dim i As Integer, j As Integer

For i = 1 to 10
For j = 1 to 10
bFound = True
Exit For
Next j

If bFound Then
Exit For
End If
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top