diff options
Diffstat (limited to 'rust/chap3/flow.rs')
| -rw-r--r-- | rust/chap3/flow.rs | 50 |
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(); +} |
