Variables With If Expressions
Let's use variables in the condition section of our if/else expression. The first step is to bind the values to our variables.
let alfa = 7;
let bravo = 8;
Then, we'll replace the numbers in the condition
section of the if
statement with the variable
names. So, this:
if 7 == 8 {
...
}
Becomes this:
if alfa == bravo {
...
}
Here's the code for the full example which outputs:
They don't match
SOURCE CODE
fn main() {
let alfa = 7;
let bravo = 8;
if alfa == bravo {
println!("They match");
} else {
println!("They don't match");
}
}