E4112#
continue 文の使い方が不正です。
ループの初期化、条件、または更新文で continue 文を使うと、このエラーが発生します。
誤った例#
///|
pub fn f(x : Int, y : Int) -> Unit {
for i = 0; i < x; i = i + 1 {
for j = ({
continue
})
j < y
j = j + 1 {
// ^^^^^^^^ Error: The usage of continue statement is invalid.
println(i + j)
}
}
}
修正方法#
ループの初期化、条件、更新文には continue 文を書かず、ループ本体に置きます。
///|
pub fn f(x : Int, y : Int) -> Unit {
for i = 0; i < x; i = i + 1 {
for j = 0; j < y; j = j + 1 {
if j == 0 {
continue
}
println(i + j)
}
}
}
continue はラベル付きブロックを対象にすることもできません。ラベル付きブロックを抜けるには break を使い、continue は外側のラベル付きループを対象にします。
///|
pub fn skip_block() -> Unit {
block~: {
continue block~
}
}
///|
pub fn skip_block() -> Unit {
block~: {
break block~
}
}