What is the main difference between while and do-while loop?

What is the main difference between while and do-while loop?

Here is the difference table:

while do-while
Condition is checked first then statement(s) is executed. Statement(s) is executed atleast once, thereafter condition is checked.
It might occur statement(s) is executed zero times, If condition is false. At least once the statement(s) is executed.

What is the main difference between a while and a do-while loop in Java?

The while loop in java executes one or more statements after testing the loop continuation condition at the start of each iteration. The do-while loop, however, tests the loop continuation condition after the first iteration has completed.

What is the difference between for loop and do-while loop in Java?

Initialization may be outside or within the loop. for loop is entry controlled loop. do-while is exit controlled loop.

Do WHILE loop syntax?

Following is the syntax of a do…while loop − do { // Statements }while (Boolean_expression); Notice that the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.

Do while vs while?

Here, the main difference between a while loop and do while loop is that while loop check condition before iteration of the loop. On the other hand, the do-while loop verifies the condition after the execution of the statements inside the loop. Furthermore, the while loop is known as the entry-controlled loop.


In this tutorial, we will learn about Nested do while loop in Cpp language In C programming language, one do-while loop inside another do-while loop is known as nested do -while loop initially, the initialization statement is executed only once and statements (do part) execute only one. Then, the flow of control evaluates the test expression.

What is an example of while loop?

A while loop is a control flow structure which repeatedly executes a block of code indefinite no. of times until the given condition becomes false. For example, say, you want to count the occurrence of odd numbers in a range. Some technical references call it a pre-test loop as it checks the condition before every iteration.