Java essentialsControl flow
Loops
6 min lesson
Loops repeat code. Use a for loop when working through a known range or collection, and a while loop when the stopping condition is more important than the count.
Keep in mind
For each iteration, make sure the loop moves toward its stopping condition.
Lesson.java
for (int lesson = 1; lesson <= 3; lesson++) {
System.out.println("Lesson " + lesson);
}What happens: Lesson 1, Lesson 2, Lesson 3