From eea33ef309ac42290911603d58af70e489829334 Mon Sep 17 00:00:00 2001 From: Tahinli <> Date: Sat, 29 Apr 2023 17:30:19 +0300 Subject: [PATCH] control_flow --- 6-control_flow/Cargo.toml | 8 ++++++ 6-control_flow/src/main.rs | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 6-control_flow/Cargo.toml create mode 100644 6-control_flow/src/main.rs diff --git a/6-control_flow/Cargo.toml b/6-control_flow/Cargo.toml new file mode 100644 index 0000000..8eb83b9 --- /dev/null +++ b/6-control_flow/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "control_flow" +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/6-control_flow/src/main.rs b/6-control_flow/src/main.rs new file mode 100644 index 0000000..82400de --- /dev/null +++ b/6-control_flow/src/main.rs @@ -0,0 +1,57 @@ +fn main() { + println!("Hello, world!"); + + let x = 3; + + if x<0 + { + println!("Below Zero"); + } + else if x==0 + { + println!("Equals Zero"); + } + else + { + println!("Above Zero"); + } + let val = true; + let x = if val {5} else {7}; + + println!("X is = {x}"); + + 'outer_loop: loop //Labeling a loop + { + println!("Outer Loop"); + 'inner_loop: loop + { + println!("Inner Loop"); + if x==5 + { + break 'outer_loop; + } + else + { + break 'inner_loop; + } + } + } + let mut y = 0; + while y==0 + { + y += 1; + } + let q = [0,1,2,3,4]; + + for element in q //For Each + { + println!("Element of Array = {element}"); + } + + for element in (0..100).rev() //Standart For + { + println!("Element = {element}"); + } + + +}