if else statements and if expressions (ternary replacement)

This commit is contained in:
Sil Klaasboer
2025-12-18 11:49:09 +01:00
parent 1529443824
commit 7b2a7eeb49
3 changed files with 36 additions and 0 deletions

7
control_flow/Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "control_flow"
version = "0.1.0"

6
control_flow/Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "control_flow"
version = "0.1.0"
edition = "2024"
[dependencies]

23
control_flow/src/main.rs Normal file
View 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)
}