Rust - Control Flow: Conditionals
Control Flow: Conditionals
if Expressions
if expressions are sometimes called arms
if number % 4 == 0 {
println!("number is divisible by 4");
} else if number % 3 == 0 {
println!("number is divisible by 3");
} else {
println!("number is not divisible by 4, 3");
}
- the condition in this code must be a bool (will not automatically try to convert non-Boolean types to a Boolean).
if in a let Statement:
let number = if condition { 5 } else { 6 };
################################################################################
################################################################################
################################################################################
Leave a Comment