VB.NET - Continue For Alternative for Visual Studio 2003

I am trying to skip to the next entry in a loop for.

For Each i As Item In Items
    If i = x Then
        Continue For
    End If

    ' Do something
Next

In Visual Studio 2008, I can use Continue For. But in VS Visual Studio 2003 this does not exist. Is there an alternative method that I could use?

+3
source share
5 answers

Well, you can just do nothing if your condition is true.

For Each i As Item in Items
    If i <> x Then ' If this is FALSE I want it to continue the for loop
         ' Do what I want where
    'Else
        ' Do nothing
    End If
Next
+4
source

Continue, from what I read, does not exist in VS2003. But you can switch your state so that it is only satisfied when the condition is not met.

For Each i As Item In Items
  If i <> x Then
    ' run code -- facsimile of telling it to continue.
  End If
End For
+2
source

, If.

For Each i As Item In Items
    If Not i = x Then 

    ' Do something
    End If
Next
+1

GoTo ​​ .

For Each i As Item In Items
    If i = x Then GoTo continue
    'Do somethingNext
    continue:
    Next
+1
source

Depending on your code, it might be redundant, but here's an alternative:

For Each i As Item In Items
    DoSomethingWithItem(i)
Next

...

Public Sub DoSomethingWithItem(i As Item)
    If i = x Then Exit Sub
    'Code goes here
End Sub
0
source

Source: https://habr.com/ru/post/1794458/


All Articles