E4148

E4148#

The loop label is undeclared.

MoonBit allows programmers to continue to or break from a loop with a label. The label must be declared at the beginning of one of the loops the continue or break statement is in.

Erroneous example#

pub fn skip_zero(values : Array[Int]) -> Unit {
  for value in values {
    if value == 0 {
      continue outer~
    //         ^~~~~
    // Error: The label outer is undeclared.
    }
    println(value)
  }
}

Suggestion#

Make sure the label is declared at the beginning of the loop the continue or break statement is in.

pub fn skip_zero(values : Array[Int]) -> Unit {
  outer~: for value in values {
    if value == 0 {
      continue outer~
    }
    println(value)
  }
}