VB.NET 2005,已经实现了continue语法,具体是这样操作:
如果 Continue 语句在 Do...Loop 循环中,请将该语句更改为 Continue Do。
如果 Continue 语句在 For...Next 循环中,请将该语句更改为 Continue For。
如果 Continue 语句在 While...End While 循环中,请将该语句更改为 Continue While。
否则,请移除 Continue 语句。
用法:
For i As Integer = 1 To 10
' If i = 5 跳过 Console.Writeline statement
If i = 5 Then Continue For
Console.WriteLine(i.ToString)
Next
' Do While using Continue statement.
Dim ii As Integer = 1
Do While ii < 10
ii += 1
' If ii = 5 跳过 Console.Writeline statement
If ii = 5 Then Continue Do
Console.WriteLine(ii.ToString)
Loop
' While using Continue statement.
Dim iii As Integer = 1
While iii < 10
iii += 1
' If iii = 5 跳过 Console.Writeline statement
If iii = 5 Then Continue While
Console.WriteLine(iii.ToString)
End While
结果:执行 continue之后,5没有输出
2
3
4
6
7
8
9
10