Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET - How to move to next item a For Each Loop?

Tags:

loops

vb.net

Is there a statment like Exit For, except instead of exiting the loop it just moves to the next item.

For example:

For Each I As Item In Items      If I = x Then          ' Move to next item     End If      ' Do something  Next 

I know could simply add an Else to the If statement so it would read as follows:

For Each I As Item In Items      If I = x Then          ' Move to next item     Else         ' Do something     End If  Next 

Just wondering if there is a way to jump to the next item in the Items list. I'm sure most will properly be asking why not just use the Else statement, but to me wrapping the "Do Something" code seems to be less readable. Especially when there is a lot more code.

like image 232
Sean Taylor Avatar asked May 06 '09 13:05

Sean Taylor


People also ask

How do you move to the next iteration in a while loop?

You can use the continue statement if you need to skip the current iteration of a for or while loop and move onto the next iteration.

How do you break a loop in Visual Basic?

When used within nested Do loops, Exit Do exits the innermost loop and transfers control to the next higher level of nesting. Immediately exits the For loop in which it appears. Execution continues with the statement following the Next statement. Exit For can be used only inside a For ...

What is for next loop in VB?

Next Loop. Advertisements. It repeats a group of statements a specified number of times and a loop index counts the number of loop iterations as the loop executes.


1 Answers

For Each I As Item In Items     If I = x Then Continue For      ' Do something Next 
like image 120
Adam Robinson Avatar answered Oct 10 '22 11:10

Adam Robinson