Do-While And Do-Until Loop
Another example for a loop structure is the Do-While and Do-Until. The Do-While structure repeats a block of statements while a condition is True.
Do While [Condition]
[Statements]
[Exit Do]
[Statements]
Loop
Do
[Statements]
[Exit Do]
[Statements]
Loop Until [Condition]
Again a practical example:
Sub ExampleWhile()
Do While PSL.Glossaries.Count > 0
PSL.Glossaries.Remove(1)
Loop
End Sub
The above example could have been made with a Do-Until structure:
Sub ExampleUntil()
Do
PSL.Glossaries.Remove(1)
Loop Until PSL.Glossaries.Count = 0
End Sub
The example deletes the glossaries from the project. The difference between those two loops structures is, that the Do-Until loop first executes the statements before the condition is checked. Under special conditions, this can cause problems. So use the Do-Until loop only if you are sure, that the statements within the loop should be executed at least one time.