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) - Java Tutorial
From the course: Learning Java 11
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Mapping out program control flow3m 57s
-
(Locked)
Operators in Java2m 26s
-
(Locked)
Decision-making with if in Java4m 8s
-
(Locked)
Understanding scope in Java1m 39s
-
(Locked)
While loops (conceptually)1m 53s
-
(Locked)
While loops in Java3m 19s
-
(Locked)
Challenge: Multiple choice2m 22s
-
(Locked)
Sample solution: Multiple choice5m 1s
-
(Locked)
-
-
-
-