From 6d09a2a420e2289702b701c35c931641494166f4 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Mon, 4 Aug 2025 08:46:58 +0200 Subject: [PATCH] finished ch3 --- ch3/branches/Cargo.lock | 7 +++++++ ch3/branches/Cargo.toml | 6 ++++++ ch3/branches/src/main.rs | 9 +++++++++ ch3/functions/Cargo.lock | 7 +++++++ ch3/functions/Cargo.toml | 6 ++++++ ch3/functions/src/main.rs | 17 +++++++++++++++++ ch3/loops/Cargo.lock | 7 +++++++ ch3/loops/Cargo.toml | 6 ++++++ ch3/loops/src/main.rs | 5 +++++ 9 files changed, 70 insertions(+) create mode 100644 ch3/branches/Cargo.lock create mode 100644 ch3/branches/Cargo.toml create mode 100644 ch3/branches/src/main.rs create mode 100644 ch3/functions/Cargo.lock create mode 100644 ch3/functions/Cargo.toml create mode 100644 ch3/functions/src/main.rs create mode 100644 ch3/loops/Cargo.lock create mode 100644 ch3/loops/Cargo.toml create mode 100644 ch3/loops/src/main.rs diff --git a/ch3/branches/Cargo.lock b/ch3/branches/Cargo.lock new file mode 100644 index 0000000..c5d0014 --- /dev/null +++ b/ch3/branches/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "branches" +version = "0.1.0" diff --git a/ch3/branches/Cargo.toml b/ch3/branches/Cargo.toml new file mode 100644 index 0000000..b12fd97 --- /dev/null +++ b/ch3/branches/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "branches" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/ch3/branches/src/main.rs b/ch3/branches/src/main.rs new file mode 100644 index 0000000..e64a42a --- /dev/null +++ b/ch3/branches/src/main.rs @@ -0,0 +1,9 @@ +fn main() { + let number = 3; + + if number < 5 { + println!("condition was true"); + } else { + println!("condition was false"); + } +} diff --git a/ch3/functions/Cargo.lock b/ch3/functions/Cargo.lock new file mode 100644 index 0000000..8a72924 --- /dev/null +++ b/ch3/functions/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "functions" +version = "0.1.0" diff --git a/ch3/functions/Cargo.toml b/ch3/functions/Cargo.toml new file mode 100644 index 0000000..9c392ab --- /dev/null +++ b/ch3/functions/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "functions" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/ch3/functions/src/main.rs b/ch3/functions/src/main.rs new file mode 100644 index 0000000..e159b51 --- /dev/null +++ b/ch3/functions/src/main.rs @@ -0,0 +1,17 @@ +fn main() { + another_function(10); + print_labeled_measurements(5, 'h'); + another_function(five()); +} + +fn another_function(x: i32) { + println!("The value of x is {x}"); +} + +fn print_labeled_measurements(value: i32, unit_label: char) { + println!("The measurement is: {value}{unit_label}"); +} + +fn five() -> i32 { + 5 +} diff --git a/ch3/loops/Cargo.lock b/ch3/loops/Cargo.lock new file mode 100644 index 0000000..7261438 --- /dev/null +++ b/ch3/loops/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "loops" +version = "0.1.0" diff --git a/ch3/loops/Cargo.toml b/ch3/loops/Cargo.toml new file mode 100644 index 0000000..a046a76 --- /dev/null +++ b/ch3/loops/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "loops" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/ch3/loops/src/main.rs b/ch3/loops/src/main.rs new file mode 100644 index 0000000..a6398af --- /dev/null +++ b/ch3/loops/src/main.rs @@ -0,0 +1,5 @@ +fn main() { + loop { + println!("Hello, world!"); + } +}