Do ... Loop, Do While..., Do Until...

Repeat a block of statements.

Syntax 
      Do [While condition]
          [Statements]
      [Exit Do]
          [Statements]
      Loop
or:
      Do [Until condition]
          [Statements]
      [Exit Do]
          [Statements]
      Loop
or:
      Do 
          [Statements]
      [Exit Do]
          [Statements]
      Loop [While condition]
or:
      Do 
          [Statements]
      [Exit Do]
          [Statements]
      Loop [Until condition]
Key
   condition   A boolean expression that evaluates to True or False

  Statements   VBScript statements to be repeated until condition is True

The keyword While will continue the loop as long as condition is True.
The keyword Until will continue the loop as long as condition is False.
If no condition is specified, the loop will repeat indefinitely or until an Exit Do is encountered.

Examples

'Count to 50
Option Explicit
Dim counter
counter = 0

Do
  counter = counter + 1
  WScript.Echo counter
Loop Until counter = 50

WScript.Echo "Final total" & counter


' Count to 100
Option Explicit
Dim i
i = 0

Do While i < 100
  i = i + 1
  WScript.Echo i
Loop

WScript.Echo "Final total" & i

“Profit in business comes from repeat customers, customers that boast about your project or service, and that bring friends with them” ~ W. Edwards Deming

Related:

For...Next - Repeat a block of statements a given number of times
For Each... - Loop through the items in a collection or array
If..Then - Conditionally execute a block of statements
Equivalent Powershell command: Do ... While


© Copyright SS64.com 1999-2013
Some rights reserved