/// https://kaisery.github.io/trpl-zh-cn/ch03-05-control-flow.html
/// 控制流
fn main() {
println!("Hello, world!");
let number = 3;
println!("First number is {number}");
let number = 7;
if number < 5 {
println!("condition was true, number less than five.");
}else{
println!("condition was false, number greater or equals to five.");
}
let number = 6;
if number % 4 == 0 {
println!("number is divisible by 4");
}else if number % 3 == 0 {
println!("number is divisible by 3");
}else if number %2 == 0 {
println!("number is divisible by 2");
}else{
println!("number is not divisible by 4 , 3 or 2");
}
let condition = true;
let number = if condition {5} else {6};
println!("The value of number is: {number}");
let mut counter = 0;
let result = loop {
counter += 1;
if counter == 10 {
break counter * 2;
}
};
}
///
/// https://kaisery.github.io/trpl-zh-cn/ch03-05-control-flow.html
/// 控制流
///
fn main() {
println!("Hello, world!");
let mut number = 3;
while number != 0 {
println!("{number}!");
number -= 1;
}
println!("LIFTOFF!!!")
}
这里记录的是Rust的控制流,也就是判定,类似Python的语法,在if后面是不需要加括号的.
标签:04,divisible,number,else,let,condition,println,Rust From: https://www.cnblogs.com/ukzq/p/18135336