If can return values

This commit is contained in:
Stephan Rehfeld 2026-04-08 17:41:15 +02:00
parent 8779759e7a
commit 72541ec0a1

View File

@ -1,12 +1,9 @@
fn main() {
let number = 24;
// Simlar as we know it from other programing languages
// No parantheses around condigition.
// Condition has to be a boolean
if number > 23 {
println!("foo");
} else {
println!("bar");
}
// if construct can return a value in Rust
// Similar to ?: Operator in C like languages
let message = if number > 23 { "foo" } else { "bar" };
println!("{}", message);
}