The usage of Do...Loop statement in VBS
This article introduces the relevant knowledge of "the use of Do...Loop sentences in VBS". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
A statement block is repeated when the condition is True or before the condition becomes True.
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
You can also use the following syntax:
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]
Parameter condition
A numeric or string expression whose value is True or False. If condition is Null, condition is treated as False.
Statements
One or more commands that are repeated when condition is True.
Description
Exit Do can only be used in Do...Loop control statements, providing another way to exit Do...Loop. You can place any Exit Do anywhere in the Do...Loop statement. Exit Do is usually used with conditional judgment statements, such as If...Then, to pass control to the statement immediately following the Loop statement.
When used in a nested Do...Loop, Exit Do passes control to the upper layer of the nested loop in which it resides.
The following example illustrates how to use the Do...Loop statement:
Do Until DefResp = vbNo MyNum = Int (6 * Rnd + 1) 'produces a random number between 1 and 6. DefResp = MsgBox (MyNum & "do you want another number?" , vbYesNo) LoopDim Check, CounterCheck = True: Counter = 0 'initialize the variable. Do 'outer loop. Do While Counter < 20 'inner loop. Counter = Counter + 1 'increments the counter. If Counter = 10 Then'if the condition is True... Check = False 'sets the flag value to False. Exit Do 'terminates the inner loop. End If LoopLoop Until Check = False 'immediately terminates the outer loop. This is the end of the introduction to "the use of Do...Loop statements in VBS". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!