1. Overview
In this article, we’ll look at a core aspect of the Java language – executing a statement or a group of statements repeatedly using a do-while loop.
2. Do-While Loop
The do-while loop works just like the while loop except for the fact that the first condition evaluation happens after the first iteration of the loop:
do {
statement;
} while (Boolean-expression);
Let’s have a look at a simple example:
int i = 0;
do {
System.out.println("Do-While loop: i = " + i++);
} while (i < 5);
3. Conclusion
In this quick tutorial, we explored Java’s do-while loop.
As always, examples can be found over on GitHub.