E4102

E4102#

Outside of a loop.

This error occurs when using break or continue statements outside of a loop construct. These control flow statements can only be used within loops.

  • break is used to exit a loop early

  • continue is used to skip to the next iteration of a loop

Using these statements outside of a loop body is invalid since there is no loop to break from or continue to the next iteration.

Erroneous example#

///|
pub fn f(xs : Array[Int]) -> Int {
  for i in xs {
    ignore(i)
  } nobreak {
    break 42
  }
  //  ^^^^^^^^ Error: 'break' outside of a loop
}

///|
pub fn g(x : Int) -> Unit {
  continue x
  // ^^^^^^^^ Error: 'continue' outside of a loop
}

Suggestion#

To fix this error, ensure that break and continue are used within a loop construct.

///|
pub fn ( : []) ->  {
  for  in  {
    if  > 0 {
      break 
    }
  } nobreak {
    0
  }
}

///|
pub fn ( : ) ->  {
  for  = ;  > 0;  =  - 1 {
    if  % 2 == 0 {
      continue
    }
    ()
  }
}