Do...Loop Statement

Repeats the statements between the Do and the Loop statement while the condition is True or until the condition becomes True.

Syntax:

Do statement


  Do {While | Until} condition = True
  ' Do While: The statement block is repeated as long as the condition is true
  ' Do Until: The statement block is repeated as long as the condition is false
     statements
     [Exit Do]
     statements
  Loop

Do...Loop statement


  Do
     statements
     [Exit Do]
     statements
  ' Loop While: The statement block repeats as long as the condition is true
  ' Loop Until: The statement block repeats until the condition is true
  Loop {While | Until} condition = True

Parameters:

The Do...Loop statement executes a loop as long as, or until, a certain condition is True. The condition for exiting the loop must be entered following either the Do or the Loop statement. The above examples are valid combinations.

condition: A comparison, numeric or Basic expression, that evaluates to either True or False.

statements: Statements that you want to repeat while or until a condition is True.

αž”αŸ’αžšαžΎβ€‹αžŸαŸαž…αž€αŸ’αžαžΈβ€‹αžαŸ’αž›αŸ‚αž„β€‹αž€αžΆαžšαžŽαŸ Exit Do αžŠαžΎαž˜αŸ’αž”αžΈβ€‹αž”αž‰αŸ’αž…αž”αŸ‹β€‹αžšαž„αŸ’αžœαž·αž›β€‹αž‡αž»αŸ†β€‹αžŠαŸ„αž™β€‹αž‚αŸ’αž˜αžΆαž“β€‹αž›αž€αŸ’αžαžαžŽαŸ’αžŒΒ αŸ” αž’αŸ’αž“αž€β€‹αž’αžΆαž…β€‹αž”αž“αŸ’αžαŸ‚αž˜β€‹αžŸαŸαž…αž€αŸ’αžαžΈβ€‹αžαŸ’αž›αŸ‚αž„β€‹αž€αžΆαžšαžŽαŸβ€‹αž“αŸαŸ‡β€‹αž“αŸ…β€‹αžαŸ’αžšαž„αŸ‹β€‹αž€αž“αŸ’αž›αŸ‚αž„β€‹αžŽαžΆβ€‹αž€αŸβ€‹αž”αžΆαž“β€‹αž€αŸ’αž“αž»αž„β€‹αžŸαŸαž…αž€αŸ’αžαžΈβ€‹αžαŸ’αž›αŸ‚αž„β€‹αž€αžΆαžšαžŽαŸ Do...LoopΒ αŸ” αž’αŸ’αž“αž€β€‹αž€αŸβ€‹αž’αžΆαž…β€‹αž€αŸ†αžŽαžαŸ‹β€‹αž›αž€αŸ’αžαžαžŽαŸ’αžŒβ€‹αž…αžΆαž€αž…αŸαž‰ αžŠαŸ„αž™β€‹αž”αŸ’αžšαžΎβ€‹αžšαž…αž“αžΆβ€‹αžŸαž˜αŸ’αž–αŸαž“αŸ’αž’ If...Then αžŠαžΌαž…β€‹αžαžΆαž„β€‹αž€αŸ’αžšαŸ„αž˜ αŸ–


  Do...
     statements
     If condition = True Then Exit Do
     statements
  Loop...

Example:


Sub ExampleDoLoop
    Dim sFile As String
    Dim sPath As String
    sPath = "c:\"
    sFile = Dir$( sPath ,22)
    If sFile <> "" Then
        Do
            MsgBox sFile
            sFile = Dir$
        Loop Until sFile = ""
    End If
End Sub

For, Select Case or While statements

Iif or Switch functions

Please support us!