January 2019
Beginner to intermediate
554 pages
13h 31m
English
Conditionals are also similar to how they're found in other languages. They follow the C-like if {} else {} structure:
// if_else.rsfn main() { let rust_is_awesome = true; if rust_is_awesome { println!("Indeed"); } else { println!("Well, you should try Rust !"); }}
In Rust, the if construct is not a statement, but an expression. In general programming parlance, statements do not return any value, but an expression does. This distinction means that if else conditionals in Rust always return a value. The value may be an empty () unit type, or it may be an actual value. Whatever remains in the last line inside the braces becomes the return value of the if else expression. It is important to note that both if ...
Read now
Unlock full access