Control flow determines the order of execution. Rust has powerful pattern matching!
if/else expressionsmatch expressionloop, while, forIn Rust, if is an expression that returns a value:
let number = if condition { 5 } else { 10 };match is Rust's powerful pattern matching:
match value {
1 => println!("one"),
2 | 3 => println!("two or three"),
4..=10 => println!("four to ten"),
_ => println!("something else"), // catch-all
}match must be exhaustive - you must handle all possible cases!
Implement the classic FizzBuzz for a single number:
"FizzBuzz" if divisible by both 3 and 5"Fizz" if divisible by 3 only"Buzz" if divisible by 5 only%Stringfizzbuzz(15) → "FizzBuzz"n % 3 == 0 to check divisibilityn.to_string() to convert number to StringString::from("...") for string literals