跳出 While...Wend 循环 [英] Break out of a While...Wend loop

查看:24
本文介绍了跳出 While...Wend 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VBA 的 While...Wend 循环.

I am using a While...Wend loop of VBA.

Dim count as Integer

While True
    count=count+1

    If count = 10 Then
        ''What should be the statement to break the While...Wend loop? 
        ''Break or Exit While not working
    EndIf
Wend

我不想使用像`While count<=10...Wend

I don't want to use condition like `While count<=10...Wend

推荐答案

While/Wend 循环只能使用 GOTO 提前退出> 或从外部块退出(Exit sub/function 或另一个可退出的循环)

A While/Wend loop can only be exited prematurely with a GOTO or by exiting from an outer block (Exit sub/function or another exitable loop)

改为使用 Do 循环:

Do While True
    count = count + 1

    If count = 10 Then
        Exit Do
    End If
Loop

或者循环一定次数:

for count = 1 to 10
   msgbox count
next

(Exit For 上面可以使用提前退出)

(Exit For can be used above to exit prematurely)

这篇关于跳出 While...Wend 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆