answersLogoWhite

0


Best Answer

A do-while loop guarantees the body of the loop will execute at least once. A while loop might not execute at all.

// this code will execute, even though the condition test will always evaluate to false

do {

// stuff

}while(false);

// this code will never execute because the condition test will always evaluate to false

while(false) {

// stuff

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

While and Do-While loops are similar in all aspects except for the fact that a do-while loop will execute the contents within the loop braces at least once irrespective of whether the loop criterion are met or not. In case of a while loop it will execute only if the condition matches but in case of a do-while loop it would execute once always and beyond that will execute only if the condition matches.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

do ... while will evaluate the condition at the end of the loop.

while... will evaluate the condition at the beginning of the loop.

do ... while will evaluate the condition at the end of the loop.

while... will evaluate the condition at the beginning of the loop.

do ... while will evaluate the condition at the end of the loop.

while... will evaluate the condition at the beginning of the loop.

do ... while will evaluate the condition at the end of the loop.

while... will evaluate the condition at the beginning of the loop.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

do ... while will evaluate the condition at the end of the loop.

while... will evaluate the condition at the beginning of the loop.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between do while and while loop in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are various loops available in java?

Java has three kinds of loops 1. For Loop 2. While Loop 3. Do - While Loop Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied. A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once. Example Declarations: for(int i = 0; i < n; i++) { ..... } while (i < n) { ... i++; } do { ... i++; } while (i < n) ;


Which Loop avoids check at every iteration?

All loops available in Java (for, while, do-while) have a loop termination condition that would get executed during every iteration of the loop. Without checking the loop condition the loop cannot be terminated and hence avoiding the loop condition check during iteration is not logic and Java does not do it.


What is the difference between a for loop and a while loop in java?

ComparisonThe conditions for both the 'while' and 'for' loop are exactly the same, but in each flow structure the conditions are placed in different locations. A 'for' loop places the full condition within the 'for' loop whereas the 'while' loop places the counter variable outside of the loop.The 'for' loop is used when the length of the loop is known whereas the 'while' loop is usually used when the length of the loop is unknown.'for' loop exampleWithin the parentheses the complete condition is contained. The condition has 3 parts delimited by a colon ';'. The first part sets the counter 'int i' to 0, the second part tells the loop to stop when the counter is 5. The third part tells java to increment the counter by 1 value each time the loop iterates.for ( int i = 0; i < 5; i++)'while' loop exampleWith the 'while' loop the counter is initialized outside of the 'while' loop. Inside the parentheses of the loop the condition is set to stop looping when the counter reaches a value of 5. Inside of the 'while' loop block the counter is set to increment by 1 value each time the loop iterates.int i = 0;while ( i < 5 ) {i++}


What are control structures used in javascript?

The control structures used in java script are if-statement, for-loop, for-in loop, while loop,do-while loop, switch-statement, with-statement. try-catch-finally statements.


How do you exit in nested loop in java?

You may exit a nested loop in Java using a break with a label for the outer loop.

Related questions

Difference between while and do while loops in java?

The most important differences are: a. The while loop starts with a condition whereas the condition is the line of code in case of a do while loop b. The do while loop is guaranteed to run the loop body atleast once even if the condition is an impossible to satisfy but such a guarantee is not available with the normal while loop


What is the difference between a do while loop and a for loop in c?

the counter variable cannot be initialized in while loop before entering into the block.


What is a nested loop in java?

A nested loop is a (inner) loop that appears in the loop body of another (outer) loop. The inner or outer loop can be any type: while, do while, or for. For example, the inner loop can be a while loop while an outer loop can be a for loop.


What is the Difference between while and do while?

Both are programming commands. A do/while loop will execute at least once. A while loop may not execute at all.


What is the difference between if and while loop?

Easy: if-else is not a loop; while, for and do-while are loops.if-else just run once, but do-while run many times.


Difference between for and while loop not in syntactically?

Well 'while' goes like this: while (condition) statement 'for': for (initialize; condition; after-each-loop) statement


What are various loops available in java?

Java has three kinds of loops 1. For Loop 2. While Loop 3. Do - While Loop Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied. A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once. Example Declarations: for(int i = 0; i &lt; n; i++) { ..... } while (i &lt; n) { ... i++; } do { ... i++; } while (i &lt; n) ;


How can you repeatedly execute a code in java script?

1) use for loop 2) do while loop


Is a while loop or a for loop faster?

No difference.


Which Loop avoids check at every iteration?

All loops available in Java (for, while, do-while) have a loop termination condition that would get executed during every iteration of the loop. Without checking the loop condition the loop cannot be terminated and hence avoiding the loop condition check during iteration is not logic and Java does not do it.


How does java command while true work?

The contents of a while loop will always execute if the statement between the while parentheses resolves to a boolean true. Hence, if you place "true" as the while statement, the loop will execute forever (until the loop is forcefully broken or the computer or process shuts down).


What is the difference between a for loop and a while loop in java?

ComparisonThe conditions for both the 'while' and 'for' loop are exactly the same, but in each flow structure the conditions are placed in different locations. A 'for' loop places the full condition within the 'for' loop whereas the 'while' loop places the counter variable outside of the loop.The 'for' loop is used when the length of the loop is known whereas the 'while' loop is usually used when the length of the loop is unknown.'for' loop exampleWithin the parentheses the complete condition is contained. The condition has 3 parts delimited by a colon ';'. The first part sets the counter 'int i' to 0, the second part tells the loop to stop when the counter is 5. The third part tells java to increment the counter by 1 value each time the loop iterates.for ( int i = 0; i < 5; i++)'while' loop exampleWith the 'while' loop the counter is initialized outside of the 'while' loop. Inside the parentheses of the loop the condition is set to stop looping when the counter reaches a value of 5. Inside of the 'while' loop block the counter is set to increment by 1 value each time the loop iterates.int i = 0;while ( i < 5 ) {i++}