Breaking Out of an If Statement

  • Thread starter Thread starter scain2004
  • Start date Start date
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
 
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.
 
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
 
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
 

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

Back
Top