Do…While Loop
Do…While Loop
The do while loop is quite similar to the while loop. But in case of do while loop the condition is evaluated after the execution of the block of code.
This means that the block of code will execute at least once, even if the condition is true or false.
Syntax
do
{
Block of code
}
while (condition);
Code:
<html>
<body>
<h2>The Do While Loop</h2>
<script>
var x =1;
do
{
document.write(x + "<br>");
x++;
}
while(x<=5)
</script>
</body>
</html>
Output: