While and while let

while condition repeats while a boolean remains true. while let reevaluates an expression and repeats while its refutable pattern matches, creating fresh bindings each time.

continue starts the next test; break exits the nearest loop. The pattern form is a natural way to drain Iterator.next().

fn main() {
  let mut index = 0
  while index < 2 {
    println(index)
    index += 1
  }
  let cursor = [2, 3, 4].iter()
  while let some(value) = cursor.next() {
    println(value)
  }
}
Output & diagnostics
Expected:
0
1
2
3
4
Ctrl/⌘+Enter runs the current lesson.