Control Flow
If/Else
Choosing a Value
In Rust if is an expression, so it can produce a value directly into a binding.
Program
Play the program to let a score choose the pass label.
if_else.rs
fn main() {
let score = 82;
let grade = if score >= 80 { "pass" } else { "retry" };
println!("{grade}");
}
if expression
`if ... else ...` evaluates to a value.
comparison
`score >= 80` produces a `bool`.
branch value
Both branches must produce the same type.