打破While ... Wend循环 [英] Break out of a While...Wend loop

查看:93
本文介绍了打破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/或另一个可退出的循环)

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

或者用于循环设置次数:

Or for looping a set number of times:

for count = 1 to 10
   msgbox count
next

(Exit For可以在上面用于过早退出)

(Exit For can be used above to exit prematurely)

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

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