-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address loop labels and continue. Fixes #1392.
- Loading branch information
1 parent
f40c71f
commit 82d3b82
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "loops" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dependencies] |
12 changes: 12 additions & 0 deletions
12
listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 |
21 changes: 21 additions & 0 deletions
21
listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters