0Pricing
Swift Academy · Lesson

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

  1. for-in Loops with Ranges
  2. while and repeat-while Loops
  3. Iterating Collections with for-in
  4. break, continue and Labeled Statements
← Back to Swift Academy