Breaking Out of an If Statement

S

scain2004

I have an IF statement within a For Next loop.

How can I break out of an IF statement and move on to the next loo
iteration
 
H

Harlan Grove

I have an IF statement within a For Next loop.

How can I break out of an IF statement and move on to the next loop
iteration?

You could use GoTo, but it's likely there's a better way. If you post your code,
someone here is likely to be able to suggest such a better way.
 
T

Tom Ogilvy

In general, this appears to be a design issue. You didn't say nested if
statements, so the general approach:
for i = 1 to 10
if condition then
' code to execute if condition is met
end if
Next
 
S

scain2004

It goes like this:

For i = 0 To counter

...some code...

If

For j = 0 To ....
If
...some code
....break out to Next i
ElseIf
...some code
...break out to Next i
ElseIf
...some code
End If
Next j

ElseIf

For j = 0 To ....
If
...some code
....break out to Next i
ElseIf
...some code
...break out to Next i
ElseIf
...some code
End If
Next j

End If

Next
 
Top