Statement
Executes a block of statements for the first time, and then repeats the block of statements repeatedly until the conditional expression is equal to false.
do
statement
while (expression) ;
Parameters
Statement
Options available. The statement to execute when expression is true . Can be a compound statement .
Expression
Options available. An expression that can be cast to Boolean true or false . If expression is true, the loop is executed again. If expression is false, the loop ends.
Description
The expression value is not checked until the first repeated execution of the loop completes, ensuring that the loop is executed at least once. Thereafter, the loop checks the expression after each successful repetition.
Example
The following example illustrates how to use the do...while statement to repeat a 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 + "<br>";
e.moveNext();
}
while (!e.atEnd());
return(s);
}
Requirements
Version 3
Please see
Break Statement | Continue Statement | For Statement | for...in Statement | While statement | labeled Statement