有没有像Exit For
这样的语句,除了不退出循环,它只是移动到下一项。
为例:
For Each I As Item In Items
If I = x Then
' Move to next item
End If
' Do something
Next
我知道可以简单地将一个Else
添加到If语句中,因此它将如下所示:
For Each I As Item In Items
If I = x Then
' Move to next item
Else
' Do something
End If
Next
只是想知道是否有方法可以跳到Items
列表中的下一项。我相信大多数人都会问,为什么不直接使用Else
语句,但对我来说,包装“做些什么”代码似乎可读性较差。尤其是当有更多的代码时。
发布于 2009-05-06 13:56:06
For Each I As Item In Items
If I = x Then Continue For
' Do something
Next
发布于 2009-05-06 13:56:38
我将使用Continue
语句:
For Each I As Item In Items
If I = x Then
Continue For
End If
' Do something
Next
请注意,这与移动迭代器本身略有不同- If
之前的任何内容都将再次执行。通常这是您想要的,但如果不是这样,您将不得不显式地使用GetEnumerator()
,然后使用MoveNext()
/Current
,而不是使用For Each
循环。
发布于 2009-05-06 13:57:04
下面是什么:
If Not I = x Then
' Do something '
End If
' Move to next item '
https://stackoverflow.com/questions/829689
复制相似问题