From the course: Learning Java 11

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

While loops (conceptually)

While loops (conceptually) - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

While loops (conceptually)

- [Instructor] If statements aren't the only way we can add decision making to our programs. We also have loops. A loop is similar to an if statement, except that it allows code to be executed repeatedly, based on a Boolean condition, instead of just one time. There are several different types of loops in Java, but the one we'll be focusing on in this course is the while loop. A while loop looks like this. We start at the start, and then follow the arrow to check a condition. If that condition evaluates to true, we execute a series of statements, and then check the condition again. If that condition is false, we exit the loop, and continue to the rest of the code. On your smartphone, you've probably listened to music, and if you find a song you like, you put it on repeat. When a song is on repeat, it plays over and over again until you take it off repeat. We can represent this type of functionality in a Java program. Filling in the condition of the while loop, we can say our condition…

Contents