JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




Do-while loop code


Tutorials Javascript

Topic

Using do-while loop in javascript?
Difference between while and do-while?


Explanation
        'do-while' loop is similar to while loop and the only difference here is that the set of statements are executed first and the condition is checked next.

Syntax:
do
{
     // set of statements that will be executed
}
while(condition)

Here the statements are added under do loop and while condition is checked at the end of loop. In 'Do While' the statements are executed once even if the condition will fail.

An example
Example Code:
<script language="javascript">
var i=0;
do
{
document.write("Testing DO-While loop");
}
while(i!=0)
</script>


Result:

In the example the condition is 'i' should not be equal to zero. The statements are executed and the condition is checked. The condition failed. The pointer comes out of the loop. So the statements are executed once even when the condition fails.





A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

Other Links

web hosting