E4107#
此 for 循环中多次声明了名称。
This error occurs when the same variable name is declared multiple times in the initialization block of a for-loop. In a for-loop’s initialization, each variable must have a unique name to avoid ambiguity about which value should be used.
错误示例#
pub fn f(x: Int) -> Unit {
for i = 0, i = 1; i < x; i = i + 1 {
// ^ --- Error: i is declared multiple times in this for-loop
println(i)
}
}
建议#
要修复此错误,您可以更改初始化块中的变量名称:
pub fn f(x: Int) -> Unit {
for i = 0, j = 1; i < x; i = i + 1 {
println(i)
}
}