if else statements and if expressions (ternary replacement)
This commit is contained in:
23
control_flow/src/main.rs
Normal file
23
control_flow/src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
fn main() {
|
||||
|
||||
//if else statements
|
||||
let mut num1 = 10;
|
||||
let mut num2 = 5;
|
||||
|
||||
if num1 < num2 {
|
||||
println!("{} is smaller then {}",num1, num2);
|
||||
}
|
||||
else
|
||||
{
|
||||
println!("{} is bigger then {}",num1,num2);
|
||||
}
|
||||
|
||||
//if expressions
|
||||
//always need a else case and must be of the same type, ternary operations do not exist but this results the same
|
||||
num1 = if num1 != num2 {5} else {15};
|
||||
println!("num 1: {}",num1)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user