E4106#
Unknown binder in the for-loop steps. Binders in the steps must be declared in the initialization block of the for-loop.
This error occurs when a variable name used in the update expressions (steps) of a for-loop is not declared in the initialization block of that loop. In a for-loop, you can only use variables in the update expressions that were previously declared when initializing the loop.
错误示例#
pub fn f(x: Int) -> Unit {
let mut j = 0
for i = 0; i < x; i = i + 1, j = j + 1 {
// ^ --- Error: Unknown binder j in the for-loop
// steps. Binders in the steps must be
// declared in the initialization
// block of the for-loop.
println(i)
println(j)
}
}
建议#
To fix this error, you can
declare the variable
j
in the initialization block of the for-loop. For example,
pub fn f(x: Int) -> Unit {
for i = 0, j = 0; i < x; i = i + 1, j = j + 1 {
println(i)
println(j)
}
}
remove the variable
j
from the update expressions. For example,
pub fn f(x: Int) -> Unit {
let mut j = 0
for i = 0; i < x; i = i + 1 {
println(i)
println(j)
j = j + 1
}
}