If can return values
This commit is contained in:
parent
8779759e7a
commit
72541ec0a1
13
src/main.rs
13
src/main.rs
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user