Instructie Do...Loop

Herhaalt de instructies tussen de instructies Do en Loop terwijl de voorwaarde True is of totdat de voorwaarde True wordt.

Syntaxis:

Instructie Do

Do {While | Until} condition = True
' Do While: Het instructieblok wordt herhaald zolang de voorwaarde waar is
' Do Until: Het instructieblok wordt herhaald zolang de voorwaarde onwaar is
   statements
   [Exit Do]
   statements
Loop

Instructie Do...Loop

Do
   statements
   [Exit Do]
   statements
' Loop While: Het instructieblok wordt herhaald zolang de voorwaarde waar is
' Loop Until: Het instructieblok wordt herhaald zolang de voorwaarde waar is
Loop {While | Until} condition = True

Parameters:

De instructie Do...Loop voert een lus uit zolang of totdat een bepaalde voorwaarde True is. De voorwaarde voor het verlaten van de lus moet worden ingevoerd na de instructie Do of Loop. Bovenstaande voorbeelden zijn geldige combinaties.

condition: Een vergelijking, numerieke of basisexpressie, die resulteert in een van beide True of False.

statements: Instructies die u wilt herhalen zolang of totdat een voorwaarde True is.

Gebruik de instructie Exit Do om de lus onvoorwaardelijk te beëindigen. U kunt deze instructie overal in een instructie Do...Loop toevoegen. U kunt ook als volgt een afsluitvoorwaarde opgeven met behulp van de structuur If...Then:

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

Voorbeeld:

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 of While instructies

Functies Iif of Switch

Help ons, alstublieft!