"继续] (对于下一次迭代)在VBScript上 [英] "Continue" (to next iteration) on VBScript
问题描述
一位同事和我试图在VBScriptFor / Next循环中找到一种相当于continue语句的方法。
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.
无处不在我们发现我们发现人们没有办法在VBScript中做这个没有讨厌的嵌套,这对我们来说不是一个选择,因为它是一个非常大的循环。
Everywhere we looked we found people had no way to do this in VBScript without having nasty nestings, which is not an option for us since it is a quite big loop.
我们来了出于这个想法。它会像继续(下一次迭代)一样工作吗?有没有人有更好的解决方法或改进建议?
We came out with this idea. Would it work just as a "continue(to next iteration)"? Does anyone have any better workaround or improvement suggestion?
For i=1 to N
For workaroundloop = 1 to 1
[Code]
If Condition1 Then
Exit For
End If
[MoreCode]
If Condition2 Then
Exit For
End If
[MoreCode]
If Condition2 Then
Exit For
End If
[...]
Next
Next
感谢您的评论
推荐答案
您的建议可行,但使用Do循环可能会更具可读性。
Your suggestion would work, but using a Do loop might be a little more readable.
这实际上是C中的一个成语 - 而不是使用goto,如果你想早点摆脱构造,你可以使用break语句进行do {} while(0)循环。
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
这篇关于"继续] (对于下一次迭代)在VBScript上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!