Is there a way to have nested for
loops in Rust and break the outer one from inside the inner one, the way one could do e.g. in Java? I know Rust supports named breaks in loop
but I can't seem to find information about the same regarding for
.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes. It uses the same syntax as lifetimes.
fn main() {
'outer: for x in 0..5 {
'inner: for y in 0..5 {
println!("{},{}", x, y);
if y == 3 {
break 'outer;
}
}
}
}
See loop labels documentation.