Do...Loop Statement

Repite as instrucións existentes entre Do e Loop mentres a condición sexa verdadeira ou ata que o sexa.

Sintaxe

Do [{While | Until} condición = verdadeira]

bloque de instrucións

[Exit Do]

bloque de instrucións

Bucle

ou

Do

bloque de instrucións

[Exit Do]

bloque de instrucións

Loop [{While | Until} condición = verdadeira]

Parámetros/Elementos

Condition: A comparison, numeric or string expression, that evaluates either True or False.

Statement block: Statements that you want to repeat while or until the condition is True.

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 following examples are valid combinations:

Sintaxe

Do While condición = verdadeira

...bloque de instrucións

Bucle

O bloque de instrucións entre Do While e Loop repítese mentres a condición siga a ser verdadeira.

Do Until condición = verdadeira

...bloque de instrucións

Bucle

O bloque de instrucións entre Do Until e Loop repítese mentres a condición siga a ser falsa.

Do

...bloque de instrucións

Loop While condición = verdadeira

O bloque de instrucións entre Do e Loop repítese mentres a condición siga a ser verdadeira.

Do

...bloque de instrucións

Loop Until condición = verdadeira

O bloque de instrucións entre Do e Loop repítese ata que a condición sexa verdadeira.

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

instrucións

If condición = verdadeira Then Exit Do

instrucións

Loop...

Exemplo


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

Precisamos da súa axuda!