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

Sean Taylor picture Sean Taylor · May 6, 2009 · Viewed 147.3k times · Source

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.

Answer

Adam Robinson picture Adam Robinson · May 6, 2009
For Each I As Item In Items
    If I = x Then Continue For

    ' Do something
Next