“Continue” (to next iteration) on VBScript

后端 未结 8 760
陌清茗
陌清茗 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
    
    0 讨论(0)
  • 2021-02-03 18:26

    We can use a separate function for performing a continue statement work. suppose you have following problem:

    for i=1 to 10
    
    if(condition) then   'for loop body'
    contionue
    End If
    
    Next
    

    Here we will use a function call for for loop body:

    for i=1 to 10
    Call loopbody()
    next
    
    function loopbody()
    
    if(condition) then   'for loop body'
    Exit Function
    End If
    
    End Function
    

    loop will continue for function exit statement....

    0 讨论(0)
提交回复
热议问题