mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-14 17:42:41 +00:00
37 lines
803 B
Rust
37 lines
803 B
Rust
// ./src/flow_control/if_else.md
|
|
|
|
|
|
fn part0() {
|
|
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 ten-fold");
|
|
|
|
// This expression returns an `i32`.
|
|
10 * n
|
|
} else {
|
|
println!(", and is a big number, halve the number");
|
|
|
|
// This expression must return an `i32` as well.
|
|
n / 2
|
|
// TODO ^ Try suppressing this expression with a semicolon.
|
|
};
|
|
// ^ Don't forget to put a semicolon here! All `let` bindings need it.
|
|
|
|
println!("{} -> {}", n, big_n);
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|