Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break out of a While...Wend loop

People also ask

Can you break out of a while loop?

To break out of a while loop, you can use the endloop, continue, resume, or return statement.

How do you end a while loop in VBA?

We can exit any Do loop by using the Exit Do statement.

What is While wend loop give an example?

This example uses the While...Wend statement to increment a counter variable. The statements in the loop are executed as long as the condition evaluates to True. Dim Counter Counter = 0 ' Initialize variable. While Counter < 20 ' Test value of Counter.

What is a While wend loop?

Advertisements. In a While…Wend loop, if the condition is True, all the statements are executed until the Wend keyword is encountered. If the condition is false, the loop is exited and the control jumps to the very next statement after the Wend keyword.


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)

Change to a Do loop instead:

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 can be used above to exit prematurely)