while and do-while Loops
Loop until a condition changes.
When Count Is Unknown
Sometimes you do not know how many passes you need ahead of time. A while loop repeats as long as a condition stays true. 🔄
The while Shape
A while loop checks its condition first, then runs the body. If the condition is false at the start, the body never runs at all.
while (condition) {
// body
}All lessons in this course
- The Classic for Loop
- while and do-while Loops
- for-in Over Collections
- break, continue, and Labels