The while Statement

In this lesson, we will explore one of Java's three loop-control statements, the while statement.


The while statement controls the execution of a while loop and has the following form:

while (condition)

Here, condition is a Boolean expression like those we encountered in the if statement. The while statement tests condition to see whether to continue the iteration. As long as condition is true, statement executes, as the following figure illustrates.

Get hands-on with 1200+ tech skills courses.