summaryrefslogtreecommitdiff
path: root/rust/chap3/flow.rs
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-09-06 09:30:14 +0200
committerCarlos Maiolino <[email protected]>2025-09-06 09:30:14 +0200
commit93b1c04a218858ecc59b6b8929103695b7b8c2a0 (patch)
tree7ae24ff4b2ef06c8d961f2c908ba8511e1fc995b /rust/chap3/flow.rs
parent973e27b243ea7f12b6743894465c67a4a6a87eb2 (diff)
Move rust playground here
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'rust/chap3/flow.rs')
-rw-r--r--rust/chap3/flow.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/rust/chap3/flow.rs b/rust/chap3/flow.rs
new file mode 100644
index 0000000..36557e5
--- /dev/null
+++ b/rust/chap3/flow.rs
@@ -0,0 +1,50 @@
+
+fn if_me() {
+ let number = 6;
+
+ if number < 5 {
+ println!("{number}");
+ } else {
+ println!("Number too high");
+ }
+
+ let choice = false;
+
+ let b = if choice { 24 } else { 64 };
+
+ println!("Choice is {b}");
+}
+
+fn loop_me() {
+
+ let mut c = 5;
+
+ /*
+ * Rust allow loops to me labeled, and use such labels into
+ * break and continue commands to decide what loop to break/continue
+ */
+ let res = 'loop_label: loop {
+ println!("Again");
+
+ if c == 0 {
+ break 'loop_label 99; // Return a value from the loop to the variable
+ }
+
+ c = c - 1;
+ };
+
+ println!("Value returned by the loop {res}");
+}
+
+fn for_me() {
+ unimplemented!();
+}
+
+fn while_me() {
+ unimplemented!();
+}
+
+fn main() {
+ if_me();
+ loop_me();
+}