Export (0) Print
Expand All

do...while Statement

Executes a statement block once, and then repeats execution of the loop until a condition expression evaluates to false.

do
   statement
while (expression)

Arguments

statement
Required. Statement to be executed if expression is true. Can be a compound statement.
expression
Required. An expression that can be coerced to Boolean true or false. If expression is true, the loop is executed again. If expression is false, the loop is terminated.

Remarks

The value of expression is not checked until after the first iteration of the loop, guaranteeing that the loop is executed at least once. Thereafter, it is checked after each succeeding iteration of the loop.

Example

The following example illustrates the use of the do...while statement to iterate the Drives collection.

function GetDriveList(){
   var fso, s, n, e, x;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   e = new Enumerator(fso.Drives);
   s = "";
   do {
      x = e.item();
      s = s + x.DriveLetter;
      s += " - ";
      if (x.DriveType == 3)
         n = x.ShareName;
      else if (x.IsReady)
         n = x.VolumeName;
      else
         n = "[Drive not ready]";
         s +=  n + "\n";
      e.moveNext();
   }
   while (!e.atEnd());
   return(s);
}

Requirements

Version 3

See Also

break Statement | continue Statement | for Statement | for...in Statement | while Statement | Labeled Statement

Show:
© 2014 Microsoft