Javascript Do While Loop

The Javascript Do While Loop will execute a block of code once, and then it will repeat the loop while a condition is true.

Syntax

<script type="text/javascript">
do{
   // Code block to be executed.
} 
while (variable<=endvalue);
</script>

Note: The <= could be anything that would fit the purpose ex. >, == or whatever.

Javascript Do While Loop Example

<!DOCTYPE html>
<html>
<head>  <!-- www.techstrikers.com -->
<title>My first Javascript code</title>   
</head>  
<body bgcolor="#bnde45">
<fieldset>
<legend>Javascript Do While Loop</legend>
<script type="text/javascript">
var j=0;
do
{
document.write("<b>The number is " + j + "</b>")
document.write("</br>")
j++
}
while (j<=10)
</script>
<p>Explanation:
<p>The for loop sets <b>i<b> equal to 0.
<p>As long as <b>i</b> is less than or equal to 10, 
the loop will continue to run.
<p><b>i</b> will increase by 1 each time the loop runs.
</fieldset>
</body>
</html>