Expressions and starting flow control in RBE
This commit is contained in:
23
rustbyexample/flow_control.d/if_else.rs
Normal file
23
rustbyexample/flow_control.d/if_else.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
fn main() {
|
||||
let n = 5;
|
||||
|
||||
if n < 0 {
|
||||
print!("{} is negative", n);
|
||||
} else if n > 0 {
|
||||
print!("{} is positive", n);
|
||||
} else {
|
||||
print!("{} is zero", n);
|
||||
}
|
||||
|
||||
let big_n = if n < 10 && n > -10 {
|
||||
println!(", and is a small number, increase net-fold");
|
||||
|
||||
10 * n
|
||||
} else {
|
||||
println!(", and is a big number, halve the number");
|
||||
|
||||
n / 2
|
||||
};
|
||||
|
||||
println!("{} -> {}", n, big_n);
|
||||
}
|
Reference in New Issue
Block a user