Java Reference

Java Reference Home | Smart Soft Home

do

Category

Loops

Description

Used to define a loop that repeats until a boolean expression becomes true. Differs from the while loop in that the boolean expression isn't evaluated until the bottom of the structure. This means that the code inside the do will always execute at least once, regardless of the boolean expression.

Example

do {
    System.out.println("Do this as long as x is less than 10");
    System.out.println("Do this as long as x is less than 10");
    System.out.println("Do this as long as x is less than 10");
} while (x<10);