For Each 语句,同样支持Exit For和Continue For。
例如下面的代码,检查集合中的每一个值,如果是北京市,则继续下一次循环,如果是重庆市,则提示“找到了”,并退出循环;如果是其它值,则显示该值:
Dim
Values As New List(Of String)
Values.Add("北京市")
Values.Add("上海市")
Values.Add("天津市")
For Each Value As String In Values
If Value = "北京市" Then
Continue for
ElseIf Value = "重庆市" Then
Output.Show("找到了!")
Exit For
End If
OutPut.Show(Value)
Next