473,855 Members | 2,141 Online

# Next iteration in a for loop?

Is there any way to "skip" iterations in a for loop?

Example :

for x = 1 to 10

if something = 1
next
endif

next

I see the Exit For, but I just need to skip iterations sometimes, not
jump out all together.

Thanks!

--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com
Nov 21 '05
23 22024
Sorry, still not following. That wasn't rewriting the loop I had to be
equivalent and with no continue.

The first example had an 'Exit While'. but that is not the same as having a
'Continue' there. And I'm not really sure what the second one was supposed
to be doing...

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Marina,

Reading it over, as always, you are right,

:-)

Therefore see bellow.

Probably this is not the one you want.

\\\See the real one behind this
While condition
While 1 = 1 'faking
If var1 = 1 Then
Dim v1 As Integer = 1 + 1
If var2 = 2 Then
Dim v2 As Integer = 1 + 1
ElseIf var3 = 5 Then
Exit While
End If
Dim v3 As Integer = 1 + 1
Else
Dim v4 As Integer = 1 + 1
End If
Dim v As Integer = 1 + 1
End While
End While
///

\\\ However I find this more readable
While condition
If var1 = 1 Then
Dim v1 As Integer = 1 + 1
If var2 = 2 Then
Dim v2 As Integer = 1 + 1
ElseIf var3 <> 5 Then
Dim v3 As Integer = 1 + 1
End If
Else
Dim v4 As Integer = 1 + 1
End If
If var3 <> 5 Then
Dim v As Integer = 1 + 1
End If
End While
///

I have not really tested the last one.
However the point is the extra condition which tell when it should be
done.

Cor

Nov 21 '05 #21
Dennis wrote:
I've been programming (both as hobby and at times professionally) before most
of you were born and I find GoTo's very useful in some situations...be ats me
why one would type several characters of code when a few would do nicely just
to maintain their "programmin g religion".. Might want to try Assembler
programming without GoTo's (Jumps as they are sometimes called).

It's always "the best tool for the job" for me. Sometimes that is a
GoTo, sometimes it isn't!

I think the religion surrounding GoTo started because it was being
overused and misused, kind of funny how that happens!

--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com
Nov 21 '05 #22
Marina,

It does not exit the while it restart the outerloop and is only exiting the
innerloop which is endless.

The second sample shows without that restarting the loop a nicer
documentative use.

Cor
Nov 21 '05 #23
Hi

So I think this is also an alternative to workaround the problem besides If
statement.
Also in vb.net 2005, there will be a new keyword Continue added.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.