E4104#
Current loop expects different number of arguments than supplied with continue
.
This error occurs when the number of arguments provided to a continue
statement does not match the number of arguments expected by the loop. In a
loop
construct, when using continue
, you must provide the same number of
arguments as declared in the loop header.
For example, if a loop
takes 2 arguments, any continue
statement within that
loop
must also provide exactly 2 arguments. Providing too few or too many
arguments will trigger this error.
Note that in a for
loop, you can omit all arguments in a continue
statement.
In this case, the loop will use the default update expressions specified in the
loop header. However, if you do provide arguments to continue
, the number of
arguments must match the number of loop variables.
For example, in a for
loop with two variables:
continue
(with no arguments) will use the default updatescontinue x, y
(with two arguments) is validcontinue x
orcontinue x, y, z
will trigger this error
错误示例#
pub fn f(x: Int, y: Int) -> Int {
loop x, y {
0, 0 => 0
a, _ => continue a - 1
// ^^^^^^^^^^^^^^ Error: Current loop expects 2 arguments, but
// `continue` is supplied with 1 arguments
}
}
pub fn g(x : Int, y : Int) -> Int {
for i = x, j = y; i + j < 10; i = i + 1, j = j + 1 {
if i < j {
continue i + 2, j + 1, i + j
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: Current loop expects 2 arguments, but
// `continue` is supplied with 3 arguments
}
} else {
42
}
}
建议#
To fix this error, ensure that the number of arguments provided to continue
matches the number of loop variables. For example,
pub fn f(x: Int, y: Int) -> Int {
loop x, y {
0, 0 => 0
a, b => continue a - 1, b - 1
}
}
pub fn g(x : Int, y : Int) -> Int {
for i = x, j = y; i + j < 10; i = i + 1, j = j + 1 {
if i < j {
continue i + 2, j + 1
} else {
continue
}
} else {
42
}
}