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

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
}

First answer by Moobler. Last edit by Moobler. Contributor trust: 354 [recommend contributor recommended]. Question popularity: 1 [recommend question].