“继续"(到下一次迭代)在 VBScript 上

编程入门 行业动态 更新时间:2024-10-28 18:29:58
本文介绍了“继续"(到下一次迭代)在 VBScript 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我和一位同事试图找出一种在 VBScriptFor/Next"循环中执行继续"语句的等效方法.

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 中的一个习惯用法 - 如果您想尽早退出该构造,则可以使用带有 break 语句的 do { } while (0) 循环来代替使用 goto.

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

正如crush所暗示的,如果你去掉额外的缩进级别,它看起来会更好一些.

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 上

本文发布于:2023-10-12 21:23:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485934.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:迭代   quot   VBScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!