C/C++'继续'在VB6中等效

Ste*_*ven 22 c vb6

是否有一个VB6等同于C/C++'continue'关键字?

在C/C++中,命令'continue'开始循环的下一次迭代.

当然,存在其他等同物.我可以将循环的剩余代码放在if语句中.或者,我可以使用goto.(啊!)

Jus*_*ier 20

在VB6中没有等价物,但VB的后续版本确实引入了这个关键字.本文有一个更深入的解释:http://vbnotebookfor.net/2007/06/04/the-continue-statement/

也许您可以重构代码以添加if语句或让循环只调用可以返回的函数.


Cra*_*ney 7

VB6没有循环的continue语句.你必须使用goto,if或其他循环来模拟它.

//VB.net
do
    if condition then continue do
    ...
loop
//VB6 equivalent (goto)
do
    if condition then goto continue_do
    ...
continue_do:
loop
//VB6 equivalent (if)
do
    if not condition then
        ...
    endif
loop
Run Code Online (Sandbox Code Playgroud)

你不能在VB6中使用"exit while".但你可以使用转到.

While condition

    if should_skip then goto mycontinue

    'code

    if should_break then goto outloop

   mycontinue:

Wend

outloop:
Run Code Online (Sandbox Code Playgroud)


Mik*_*ike 6

可悲的是,如果VB6没有继续 - 这是VB 2005中的新功能我相信.

我不会总是害怕goto语句 - 这实际上是Continue是什么,但是在循环之后不需要标记的行.只要你的goto语句没有跳得很远,它们将始终是可读的,它可能是解决这个问题的最优雅的解决方案.

在for循环中嵌入另一个if/then/else实际上比一个简单的简单goto更加难以读取和维护(在goto行上注释说"'read as Continue For").

祝好运!