diff options
| author | Mathieu David <mathieudavid@mathieudavid.org> | 2015-05-31 20:56:35 +0200 |
|---|---|---|
| committer | Mathieu David <mathieudavid@mathieudavid.org> | 2015-05-31 20:56:35 +0200 |
| commit | 151c3d3644c2d8b21465dd8a48ad753539e18c88 (patch) | |
| tree | 8e019494416d00fcef8fe48125fe96503185d220 | |
| parent | 6e2f18ef322c094ed49eee11994fc49c5cacbc2a (diff) | |
| download | rust-151c3d3644c2d8b21465dd8a48ad753539e18c88.tar.gz rust-151c3d3644c2d8b21465dd8a48ad753539e18c88.zip | |
Corrected some formatting issues
| -rw-r--r-- | src/doc/trpl/for-loops.md | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/doc/trpl/for-loops.md b/src/doc/trpl/for-loops.md index c8422f351d1..9cd1689cf3d 100644 --- a/src/doc/trpl/for-loops.md +++ b/src/doc/trpl/for-loops.md @@ -42,35 +42,41 @@ Rust does not have the “C-style” `for` loop on purpose. Manually controlling each element of the loop is complicated and error prone, even for experienced C developers. -# Loopcounter +# Enumerate When you need to keep track of how many times you already looped, you can use the `.enumerate()` function. -#### On ranges: +## On ranges: ```rust for (i,j) in (5..10).enumerate() { println!("i = {} and j = {}", i, j); } ``` + Outputs: -``` + +```rust i = 0 and j = 5 i = 1 and j = 6 i = 2 and j = 7 i = 3 and j = 8 i = 4 and j = 9 ``` + Don't forget to add the parentheses around the range. -#### On iterators: +## On iterators: + ```rust for (linenumber, line) in lines.enumerate() { println!("{}: {}", linenumber, line); } ``` + Outputs: -``` + +```rust 0: Content of line one 1: Content of line two 2: Content of line tree |
