GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing www.geeksforgeeks.org — JavaScript do...while Loop - GeeksforGeeks JavaScript do...while LoopLast Updated : 23 Jul, 2025 A do...while loop in JavaScript is a control structure where the code executes repeatedly based on a given boolean condition. It's similar to a repeating if statement. One key difference is that a do...while loop guarantees that the code block will execute at least once, regardless of whether the condition is met initially or not. There are mainly two types of loops.
Syntax: do {
// Statements
}
while(conditions)Example 1: In this example, we will illustrate the use of a do...while loop
Output: 1
2
3
4
5The 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 Example 2: In this example, we will try to understand the difference between the two loops
Output: 1Explanation: We can see that even if the condition is not satisfied in the do...while loop the code still runs once, but in the case of while loop, first the condition is checked before entering into the loop. Since the condition does not match therefore the while loop is not executed. Let us compare the while and do...while loop
Supported Browser:
We prefer you to check this article to know more about JavaScript Loop Statements. Comment Explore | ||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |