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
for loop with explicit loop variables, when using continue with arguments,
you must provide the same number of arguments as declared in the loop header.
For example, if a for loop has two loop variables, any continue statement
with arguments within that loop must also provide exactly two 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 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 xorcontinue x, y, zwill trigger this error
Erroneous example#
///|
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
}
} nobreak {
42
}
}
Suggestion#
To fix this error, ensure that the number of arguments provided to continue
matches the number of loop variables. For example,
///|
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
}
} nobreak {
42
}
}