VBA - Do-Until Loops - Tutorialspoint
Có thể bạn quan tâm
A DoUntil loop is used when we want to repeat a set of statements as long as the condition is false. The condition may be checked at the beginning of the loop or at the end of loop.
Syntax
Following is the syntax of a Do..Until loop in VBA.
Do Until condition [statement 1] [statement 2] ... [statement n] [Exit Do] [statement 1] [statement 2] ... [statement n] LoopFlow Diagram
Example
The following example uses DoUntil loop to check the condition at the beginning of the loop. The statements inside the loop are executed only if the condition is false. It exits out of the loop, when the condition becomes true.
Private Sub Constant_demo_Click() i = 10 Do Until i>15 'Condition is False.Hence loop will be executed i = i + 1 msgbox ("The value of i is : " & i) Loop End SubWhen the above code is executed, it prints the following output in a message box.
The value of i is : 11 The value of i is : 12 The value of i is : 13 The value of i is : 14 The value of i is : 15 The value of i is : 16Alternate Syntax
There is also an alternate syntax for Do...Until loop which checks the condition at the end of the loop. The major difference between these two syntax is explained with the following example.
Do [statement 1] [statement 2] ... [statement n] [Exit Do] [statement 1] [statement 2] ... [statement n] Loop Until conditionFlow Diagram
Example
The following example uses Do...Until loop to check the condition at the end of the loop. The statements inside the loop are executed at least once, even if the condition is True.
Private Sub Constant_demo_Click() i = 10 Do i = i + 1 msgbox "The value of i is : " & i Loop Until i<15 'Condition is True.Hence loop is executed once. End SubWhen the above code is executed, it prints the following output in a message box.
The value of i is : 11 vba_loops.htm Print Page Previous Next AdvertisementsTừ khóa » Visual Basic Do Until
-
Do...Loop Statement - Visual Basic - Microsoft Docs
-
Vòng Lặp Do-Until Trong VBA - VietTuts
-
Thực Hành Với Visual Basic: Cấu Trúc Lặp Do ... Loop While
-
While Loop, Do While Loop, Do Until Loop, While End While - VB.NET
-
Hướng Dẫn Cách Viết Vòng Lặp Do Loop Trong VBA - Học Excel Online
-
Visual Basic Do ... Loops
-
Visual Basic Tutorial - 30 - Do Until Loop - YouTube
-
VB.NET Do Until Loops - Dot Net Perls
-
Visual Basic (VB) Do While Loop - Tutlane
-
Visual Basic Do Loops | The Coding Guys
-
Guide: Do Until Loops In VBA - Software Solutions Online
-
Do Until Loop Excel VBA
-
Loops (Repetition Structures) In Visual Basic 6
-
Do Until Loop In Excel VBA (In Easy Steps)