跳至主要內容

逻辑控制

chanchaw小于 1 分钟vb6

循环

跳出本次循环

' 通过 goto 跳转
Private Sub Command1_Click()
    Dim i As Integer

    For i = 1 To 10
        If i Mod 2 = 0 Then GoTo ContinueLoop ' 如果是偶数,跳过
        Debug.Print "Processing: " & i
        ContinueLoop:
    Next i
End Sub

' do while 中的 continue
Private Sub Command3_Click()
    Dim i As Integer
    i = 1

    Do While i <= 10
        If i Mod 2 = 0 Then
            i = i + 1
            ' 跳过后直接继续下一次循环
            Continue Do
        End If

        Debug.Print "Processing: " & i
        i = i + 1
    Loop
End Sub