Enable JavaScript in the browser to display LibreOfficeDev Help pages.

XDQHo‖

muTe9‖Do...Loop Statement

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

FVEx2‖Syntax:

aiGhW‖Do statement


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

Dsqzg‖Do...Loop statement


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

WADQ4‖Parameters:

YFnQL‖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.

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

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

iXQfC‖Use the Exit Do statement to unconditionally end the loop. You can add this statement anywhere in a Do...Loop statement. You can also define an exit condition using the If...Then structure as follows:


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

EFSA4‖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

FZoqi‖For, Select Case or While statements

BB6L9‖Iif or Switch functions