A do… while loop in JavaScript is a control statement in which the code is allowed to execute continuously based on a given boolean condition. It is like a repeating if statement.
The do…while loop can be used to execute a specific block of code at least once.
do {
// Statements
}
while(conditions)
The main difference between do…while and while loop is that it is guaranteed that do…while loop will run at least once. Whereas, the while loop will not run even once if the given condition is not satisfied.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = 1;
do{
document.write(a + " Hello Yahoo Baba<br>");
a++;
}while(a <= 10)
</script>
</head>
<body>
</body>
</html>