标题: 怎样跳出while循环 [打印本页] 作者: 7house 时间: 2009-5-8 15:30 标题: 怎样跳出while循环 while XXXXX.exit
AAA
BBB
If YYYY.exist=False Then break '跳出While循环
End If
CCC
DDD
WEnd
在运行到break是出错,我试了exit, 也不行,哪位高手知道要怎么跳出while loop啊?作者: Gerrard 时间: 2009-5-8 15:46
建议用do loop 然后exit do作者: hsjzfling 时间: 2009-5-8 15:50 标题: 有问题,先查帮助 Exits a block of Do...Loop, For...Next, Function, or Sub code.
Exit Do
Exit For
Exit Function
Exit Property
Exit Sub
The Exit statement syntax has these forms:
Statement Description
Exit Do Provides a way to exit a Do...Loop statement. It can be used only inside a Do...Loop statement. Exit Do transfers control to the statement following the Loop statement. When used within nested Do...Loop statements, Exit Do transfers control to the loop that is one nested level above the loop where it occurs.
Exit For Provides a way to exit a For loop. It can be used only in a For...Next or For Each...Next loop. Exit For transfers control to the statement following the Next statement. When used within nested For loops, Exit For transfers control to the loop that is one nested level above the loop where it occurs.
Exit Function Immediately exits the Function procedure in which it appears. Execution continues with the statement following the statement that called the Function.
Exit Property Immediately exits the Property procedure in which it appears. Execution continues with the statement following the statement that called the Property procedure.
Exit Sub Immediately exits the Sub procedure in which it appears. Execution continues with the statement following the statement that called the Sub.
The following example illustrates the use of the Exit statement:
Sub RandomLoop
Dim I, MyNum
Do ' Set up infinite loop.
For I = 1 To 1000 ' Loop 1000 times.
MyNum = Int(Rnd * 100) ' Generate random numbers.
Select Case MyNum ' Evaluate random number.
Case 17: MsgBox "Case 17"
Exit For ' If 17, exit For...Next.
Case 29: MsgBox "Case 29"
Exit Do ' If 29, exit Do...Loop.
Case 54: MsgBox "Case 54"
Exit Sub ' If 54, exit Sub procedure.
End Select
Next
Loop
End Sub
"Unlike the Do loop, you do not have the option of using either While or Until, nor can you place the condition at the end of the loop. The condition for whether to loop again can only be placed at the beginning of the loop, as you see here. Finally, a significant limitation of the While…Wend loop is that there is no equivalent to Exit For or Exit Do, meaning you cannot forcibly break out of the loop." - VBScript Programmer's Reference