难道......循环
使用 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