summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels')
-rw-r--r--src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock5
-rw-r--r--src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt13
-rw-r--r--src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs21
4 files changed, 45 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock
new file mode 100644
index 000000000..f73867315
--- /dev/null
+++ b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock
@@ -0,0 +1,5 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "loops"
+version = "0.1.0"
diff --git a/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml
new file mode 100644
index 000000000..810e8bbc0
--- /dev/null
+++ b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "loops"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt
new file mode 100644
index 000000000..d4d322fb4
--- /dev/null
+++ b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt
@@ -0,0 +1,13 @@
+$ cargo run
+ Compiling loops v0.1.0 (file:///projects/loops)
+ Finished dev [unoptimized + debuginfo] target(s) in 0.58s
+ Running `target/debug/loops`
+count = 0
+remaining = 10
+remaining = 9
+count = 1
+remaining = 10
+remaining = 9
+count = 2
+remaining = 10
+End count = 2
diff --git a/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs
new file mode 100644
index 000000000..dd8856403
--- /dev/null
+++ b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs
@@ -0,0 +1,21 @@
+fn main() {
+ 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!("End count = {count}");
+}