diff options
author | garhve <git@garhve.com> | 2022-12-22 18:03:28 +0800 |
---|---|---|
committer | garhve <git@garhve.com> | 2022-12-22 18:03:28 +0800 |
commit | 36920adbaa85bd1be5ad37d7a22212231179930f (patch) | |
tree | 4cdc0aaaff479b6f41b39d68e7ba49d53867b096 /rust/theBook/chapter-3-variables-and-mutability/control-loops/src/main.rs | |
parent | b5aa889f7fced8ba2cc1698ae9696d7bd0ca8ab5 (diff) |
finish chapter 3
Diffstat (limited to 'rust/theBook/chapter-3-variables-and-mutability/control-loops/src/main.rs')
-rw-r--r-- | rust/theBook/chapter-3-variables-and-mutability/control-loops/src/main.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/rust/theBook/chapter-3-variables-and-mutability/control-loops/src/main.rs b/rust/theBook/chapter-3-variables-and-mutability/control-loops/src/main.rs new file mode 100644 index 0000000..e0e6f4c --- /dev/null +++ b/rust/theBook/chapter-3-variables-and-mutability/control-loops/src/main.rs @@ -0,0 +1,42 @@ +fn main() { + let mut counter = 0; + + let result = loop { + counter += 1; + + if counter == 10 { + break counter * 2; + } + }; + + println!("the result is {result}"); + + let mut count = 0; + + 'counting_up: loop { + println!("count = {count}"); + let mut remaining = 10; + + loop { + println!("remaining = {remaining}"); + + if remaining == 9 { + break; + } + if count == 2 { + break 'counting_up; + } + remaining -= 1; + } + + count += 1; + } + println!("count = {count}"); + + let mura = [1,2,3,4,5]; + + for a in mura.into_iter() { + println!("{a}"); + } + println!("{:?}",mura); +} |