Error codes

E0244: break or continue outside a loop

In a terminal: auk explain E0244 prints this page.

On this page

break and continue only make sense inside for, while or loop. A closure body is a separate function, so they can't reach a loop outside it either.

Wrong#

auk
fn main() {
  if true { break }
}

Fixed#

auk
fn main() {
  for i in 0..3 {
    if i == 1 { break }
  }
}

Common causes#

  • break used to leave a function: use return.
  • break inside a closure passed to map/each: use a for loop, or take_while.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page