while & do-while Loops

In this lesson, an introduction of the while and do-while loops in Java is provided. It uses coding examples to show their implementation and explain their workings.

Loops allow a programmer to execute the same block of code repeatedly.

The while loop

The while loop is really the only necessary repetition construct. It will keep running the statements inside its body until some condition is met.

The syntax is as follows:

Get hands-on with 1200+ tech skills courses.