使用Do...Loop重复的语句块While或Until条件为真,一开始或在循环的末尾或者检查条件。
Dim x As Integer = 0 Do Console.Write(x & " ") x += 1 Loop While x < 10
要么
Dim x As Integer = 0 Do While x < 10 Console.Write(x & " ") x += 1 Loop
0 1 2 3 4 5 6 7 8 9
Dim x As Integer = 0 Do Console.Write(x & " ") x += 1 Loop Until x = 10
要么
Dim x As Integer = 0 Do Until x = 10 Console.Write(x & " ") x += 1 Loop
0 1 2 3 4 5 6 7 8 9
Continue Do 可用于跳到循环的下一个迭代:
Dim x As Integer = 0 Do While x < 10 x += 1 If x Mod 2 = 0 Then Continue Do End If Console.Write(x & " ") Loop
1 3 5 7 9
您可以使用Exit Do-终止循环-请注意,在此示例中,缺少任何条件都会导致无限循环:
Dim x As Integer = 0 Do Console.Write(x & " ") x += 1 If x = 10 Then Exit Do End If Loop
0 1 2 3 4 5 6 7 8 9