Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE

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.

Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – REST with Spring (eBook) (everywhere)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.