[Solved] Conditional Next of a loop
Posted: Wed Feb 28, 2018 10:37 am
Hi All,
For I = 1 To 10
If I = 5 Then
Exit For
End If
' ... Inner part of loop
Next I
This is easy.
But, I do not want to Exit the For, instead I want to skip the rest of the inner part of the loop and go for the Next I. So I want to do something like:
For I = 1 To 10
If <condition> Then
Next I <----- This is the bit I want...
End If
' ... Inner part of loop
Next I
But it does not work when I code this.
Without coding any other costly loops, checks, or moving " ' ... Inner part of loop " into the Then/Else part of the If (which is decreasing the readability)... is there a way to do this?
Thanks in advance.
Regards,
For I = 1 To 10
If I = 5 Then
Exit For
End If
' ... Inner part of loop
Next I
This is easy.
But, I do not want to Exit the For, instead I want to skip the rest of the inner part of the loop and go for the Next I. So I want to do something like:
For I = 1 To 10
If <condition> Then
Next I <----- This is the bit I want...
End If
' ... Inner part of loop
Next I
But it does not work when I code this.
Without coding any other costly loops, checks, or moving " ' ... Inner part of loop " into the Then/Else part of the If (which is decreasing the readability)... is there a way to do this?
Thanks in advance.
Regards,