E4133

E4133#

This for .. in loop has incorrect number of loop variables.

MoonBit supports only one or two loop variables in for .. in loop.

  • One loop variable is used for the content of the iterable.

  • Two loop variables are used for the index and the content of the iterable respectively.

错误示例#

fn main {
  for a, b, c in [1, 2, 3] { // Error: This `for .. in` loop has 3 loop variables, but at most 2 is expected.
    ...
  }
}

建议#

If you want to iterate over the index and the content of the iterable, you can use two loop variables:

fn main {
  for i, v in [1, 2, 3] {
    ...
  }
}

If you want to iterate over a iterable of tuples, then you need to explicitly destructure the tuple inside the loop body:

fn main {
  for v in [(1, 2, 3), (4, 5, 6)] {
    let (a, b, c) = v
    ...
  }
}