Rust循环
Rust 提供了一个loop关键字来表示一个无限循环。
break语句可以用来退出循环,在任何时候, continue语句可用于跳过循环的剩余部分,并开始一个新的开始。
break语句可以用来退出循环,在任何时候, continue语句可用于跳过循环的剩余部分,并开始一个新的开始。
fn main() {
let mut count = 0u32;
println!("Let's count until infinity!");
// Infinite loop
loop {
count += 1;
if count == 3 {
println!("three");
// Skip the rest of this iteration
continue;
}
println!("{}", count);
if count == 5 {
println!("OK, that's enough");
// Exit this loop
break;
}
}
}
本站文章除注明转载外,均为本站原创或编译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创优秀实例教程
转载请注明:文章转载自:代码驿站 [http:/www.codeinn.net]
本文标题:Rust循环
本文地址:http://www.codeinn.net/rust/1313.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创优秀实例教程
转载请注明:文章转载自:代码驿站 [http:/www.codeinn.net]
本文标题:Rust循环
本文地址:http://www.codeinn.net/rust/1313.html

