Home > Java > Loops > Do While Loop > Definitions
Top 10 Do While Loop Definitions
1
The do while construct consists of a block of code and a condition. First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false. Because do while loops check the condition after the block is executed, the control structure is often also known as a post-test loop. Contrast with the while loop, which tests the condition before the code within the block is executed.
2
The difference between do-while and while is that do-while evaluates its expression at the bottom of the loop instead of the top. Therefore, the statements within the do block are always executed at least once.
3
In some conditions in java, you need to run some statements and processes once at least. For that you have to use the do while loop in after that check the condition then we use the do-while loop statement. do-while loop is same as the while loop statement but while loop checks the certain condition is first and if condition is true then statements or processes are executed otherwise all the statements written under the while loop is ignored by the interpreter but do - while loop executes all the statements first at once and then check the condition if the condition is true then all the statements are also executed in second times otherwise second times ignored all the statements.
4
When you want to test at the end to see whether something should be repeated, the do..while statement is the natural choice.
5
The sole difference between while and do-while is that the statement of the do-while always executes at least once, even if the expression evaluates to false the first time. In a while, if the conditional is false the first time the statement never executes. In practice, do-while is less common than while.
6
In a do-while loop, the while conditional statement appears at the end of the loop. Even if it is initially false, the statements in the loop are executed once.
7
The do-while loop always executes its body at least once, because its conditional expression is at the bottom of the loop.
