while and repeat-while Loops
Condition-based loops and guaranteeing at least one execution with repeat-while.
Welcome
When the number of iterations isn't known in advance, `while` and `repeat-while` loops are the right choice. Let's see when and how to use each.
The while Loop
A `while` loop evaluates its condition *before* each iteration:
```swift
var count = 0
while count < 5 {
print(count)
count += 1
}
// prints 0, 1, 2, 3, 4
```
If the condition is false initially, the body never runs.
All lessons in this course
- for-in Loops with Ranges
- while and repeat-while Loops
- Iterating Collections with for-in
- break, continue and Labeled Statements