While Loop Basics
Understand while basics: init, condition, update, patterns, and avoiding infinite loops.
Loop Concept
What is a loop? A loop repeats a block while a condition is true. Use it to avoid writing the same line many times.
- Start with a clear goal
- Decide what to repeat
- Stop when the task is done
While Syntax
While syntax
int count = 1;
while (count <= 3) {
System.out.println("Loop " + count);
count = count + 1;
}
Condition is checked before each iteration.
All lessons in this course
- While Loop Basics
- Do-While & When to Use It