Learn Java Script, The do…while Statement, Lesson No. 24
The do…while statement executes a loop until a condition becomes false. The syntax of the do…while statement is outlined below:
do {
statements;
} while (condition)
The difference between the do…while loop and the while loop is that the do…while loop always executes at least once. This is because the condition is checked at the end of the first execution of the loop instead of at the beginning. However, you can use either style to achieve the same end, as demonstrated in the next example.
<HTML>
<HEAD>
<TITLE>Script 2.14 – Demonstration of the do…while
statement</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE=”JavaScript” TYPE=”Text/JavaScript”>
<!– Start hiding JavaScript statements
var counter = 10;
document.write(“<B>Watch me count backwards!</B><BR>”);
do {
counter;
document.write(“counter = “, counter , “<BR>”);
} while (counter > 0)
// End hiding JavaScript statements –>
</SCRIPT>
</BODY>
</HTML>
Using the for…in statement to loop through the screen object’s properties