The do-while Loop in Java


The do-while loop is similar to the while loop, but it guarantees that the loop body is executed at least once.

Source Code

int i = 0;
do {
    System.out.println("i is: " + i);
    i++;
} while (i < 5);

Use a do-while loop when the loop body needs to be executed at least once.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments