“Continue” (to next iteration) on VBScript

后端 未结 8 762
陌清茗
陌清茗 2021-02-03 17:43

A colleague and I were trying to figure out a way of doing the equivalent of a \"continue\" statement within a VBScript \"For/Next\" loop.

Everywhere we looked we found

8条回答
  •  [愿得一人]
    2021-02-03 18:24

    I use to use the Do, Loop a lot but I have started using a Sub or a Function that I could exit out of instead. It just seemed cleaner to me. If any variables you need are not global you will need to pass them to the Sub also.

    For i=1 to N
     DoWork i
    Next
    
    Sub DoWork(i)
        [Code]
        If Condition1 Then
          Exit Sub
        End If
    
        [MoreCode]
        If Condition2 Then
          Exit Sub
        End If
    
        [MoreCode]
        If Condition2 Then
          Exit Sub
        End If
    
        [...]
    End Sub
    

提交回复
热议问题