JavaScript do while loop

The JavaScript do while loop iterates the loop while loop, but, the difference is that the loop is executed at least once even when the condition is false.

With a do-while loop the block of code executed once, and then the condition is checked, if the condition is true or false. If it is true then the loop gets executed one more time otherwise gets terminated if the condition evaluates to false.


Syntax
do {
// code to be executed
}
while (condition);


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> JavaScript dowhile Loop Statement </title>
</head>
<body>
<script>
var i=1;
do{
document.write(i + "<br/>");
i++;
} while (i<=5);
</script>
</body>
</html>

Output

JavaScript dowhile Loop Statement








Become a Patron!

Note: If the updated content is not visible to you please refresh the cookies by pressing CTRL + Shift + R.