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.

错误示例#

fn read() -> @bytes.View {
  ...
}

fn main {
  loop read() {
    [] => break
    _ => continue read~ read()
    //            ^~~~~
    // Error: The label read is undeclared.
  }
  // Defining the label here does not work since continue cannot jump to a different loop.
  read~: loop read() {
    [] => break
  }
}

建议#

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

fn main {
  read~: loop read() {
    [] => break
    _ => continue read~ read()
  }
}