From 36920adbaa85bd1be5ad37d7a22212231179930f Mon Sep 17 00:00:00 2001 From: garhve Date: Thu, 22 Dec 2022 18:03:28 +0800 Subject: finish chapter 3 --- .../control-if/Cargo.toml | 8 ++++++++ .../control-if/src/main.rs | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 rust/theBook/chapter-3-variables-and-mutability/control-if/Cargo.toml create mode 100644 rust/theBook/chapter-3-variables-and-mutability/control-if/src/main.rs (limited to 'rust/theBook/chapter-3-variables-and-mutability/control-if') diff --git a/rust/theBook/chapter-3-variables-and-mutability/control-if/Cargo.toml b/rust/theBook/chapter-3-variables-and-mutability/control-if/Cargo.toml new file mode 100644 index 0000000..141fef0 --- /dev/null +++ b/rust/theBook/chapter-3-variables-and-mutability/control-if/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "control-if" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/rust/theBook/chapter-3-variables-and-mutability/control-if/src/main.rs b/rust/theBook/chapter-3-variables-and-mutability/control-if/src/main.rs new file mode 100644 index 0000000..8866444 --- /dev/null +++ b/rust/theBook/chapter-3-variables-and-mutability/control-if/src/main.rs @@ -0,0 +1,19 @@ +fn main() { + let number = 3; + + if number < 5 { + println!("number is less than 5"); + } else { + println!("number is bigger than 5"); + } + + let use_let = if number < 5 {number} else {5}; + + println!("number is {use_let}"); + + println!("number is {}", if number < 5 {4} else {6}); + + let names = ["name", "is", "idiot"]; + + println!("names: {:?}",names); +} -- cgit v1.2.3-70-g09d2