while expressions
The while
keyword works very similar to other languages:
fn main() {
let mut x = 10;
while x != 1 {
x = if x % 2 == 0 {
x / 2
} else {
3 * x + 1
};
}
println!("Final x: {x}");
}
The while
keyword works very similar to other languages:
fn main() {
let mut x = 10;
while x != 1 {
x = if x % 2 == 0 {
x / 2
} else {
3 * x + 1
};
}
println!("Final x: {x}");
}
本文档使用 BookStack 构建