Home » Online Computer Education » Learn Java Script, The do…while Statement, Lesson No. 24

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

10

About

The main objective of this website is to provide quality study material to all students (from 1st to 12th class of any board) irrespective of their background as our motto is “Education for Everyone”. It is also a very good platform for teachers who want to share their valuable knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *