The expression is not evaluated until after the do loop's code is executed.
Therefore the code in a do loop is guaranteed to execute at least once.
do{
repeated_statement_or_block
}while (boolean_condition);
do-while loop always executes the body at least once
publicclass MainClass {
publicstaticvoid main(String[] argv) {
do {
System.out.println("here");
} while (false);
}
}
class MainClass{
publicstaticvoid main(String[] args) {
boolean finished = false;
do {
double d = Math.random();
if(d > .5) finished = true;
System.out.println(d);
} while (!finished);
}
}