VBA - how to conditionally skip a for loop iteration

后端 未结 6 1247
Happy的楠姐
Happy的楠姐 2020-11-30 01:23

I have a for loop over an array. What I want to do is test for a certain condition in the loop and skip to the next iteration if true:

For i = LBound(Schedul         


        
6条回答
  •  囚心锁ツ
    2020-11-30 02:00

    You can use a kind of continue by using a nested Do ... Loop While False:

    'This sample will output 1 and 3 only
    
    Dim i As Integer
    
    For i = 1 To 3: Do
    
        If i = 2 Then Exit Do 'Exit Do is the Continue
    
        Debug.Print i
    
    Loop While False: Next i
    

提交回复
热议问题