Does anyone know of the vb.net equivelent to the c# continue so I can exit the immediate iteration of a for loop and continue with the next one.
vb.net equivalent to c# continue
Collapse
X
-
Originally posted by lathamikDoes anyone know of the vb.net equivelent to the c# continue so I can exit the immediate iteration of a for loop and continue with the next one.
Code:Dim j As Integer For i As Integer = 1 To 4 If i = 3 Then Exit For j = i Next i MsgBox(j) ' will give 2
-
Sorry Sammy, close but no cigar. Continue doesn't drop out of the loop, it skips to the next iteration.
In VB6, at least, I don't think there is an equivalent of continue. I seem to recall hearing recently about something in VB.Net which would do it, but don't remember what it was.
In VB6, I tend to use an inner loop to achieve the same end. For example...
Code:For Index = 1 to 10 [B]Do[/B] If some condition Then [B]Exit Do[/B] ' Equivalent of applying Continue to the For loop. End If ... other processing that you wanted to skip ... [B]Loop While False[/B] ' In other words, [I]don't[/I] loop. Next
Comment
-
> Sorry Sammy, close but no cigar. Continue doesn't drop out of the loop, it skips to the next iteration.
Yep, sorry, I didn't read past "exit"
http://msdn2.microsoft.com/en-us/lib...6t(VS.71).aspx says
"Visual Basic .NET does not support the Continue statement of previous versions of Visual Basic. However, you can achieve the same functionality by putting a statement label on the Loop statement and branching to it from the middle of the loop."
Too bad it's in C#! Makes for ghasty code. And Microsoft's solution of a statement label is just as bad. Just rewrite the loop and make it readable.Comment
-
Originally posted by SammyBToo bad it's in C#! Makes for ghasty code. And Microsoft's solution of a statement label is just as bad. Just rewrite the loop and make it readable.
I'd like to know which "previous versions of VB" they're referring to, as VB6 certainly doesn't have a Continue statement.Comment
-
Originally posted by Killer42I partially agree. I love the ability to skip to the next iteration (it's available in the mainframe language that I use) and really miss it in VB. But MS's workaround sounds really ugly.
I'd like to know which "previous versions of VB" they're referring to, as VB6 certainly doesn't have a Continue statement.Comment
-
i don't know where you all get your (out-dated) info. at http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx you can find the VB.NET 'continue' statement which uses an additional 'do', 'for', or 'while':
"Continue For" for the C# equivalent of 'continue' in a for loop.
It was added in Visual Basic 2005 (VB 8). reference: http://en.wikipedia.org/wiki/Visual_Basic_.NETLast edited by humilulo; Mar 1 '13, 02:42 PM. Reason: more details on when VB "continue" was added to VB.Comment
-
Well, I think the basic problem here is that the question was asked in the pre-dot-net VB forum. Someone (such as myself) really should have directed the poster to the VB.Net forum for more up-to-date info.
Of course this may all be a little late, given this thread is about 6 years old.Comment
Comment