“Continue” (to next iteration) on VBScript

后端 未结 8 763
陌清茗
陌清茗 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:11

    Your suggestion would work, but using a Do loop might be a little more readable.

    This is actually an idiom in C - instead of using a goto, you can have a do { } while (0) loop with a break statement if you want to bail out of the construct early.

    Dim i
    
    For i = 0 To 10
        Do
            If i = 4 Then Exit Do
            WScript.Echo i
        Loop While False
    Next
    

    As crush suggests, it looks a little better if you remove the extra indentation level.

    Dim i
    
    For i = 0 To 10: Do
        If i = 4 Then Exit Do
        WScript.Echo i
    Loop While False: Next
    

提交回复
热议问题