Skip to content

Commit 151c3d3

Browse files
committed
Corrected some formatting issues
1 parent 6e2f18e commit 151c3d3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/doc/trpl/for-loops.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,41 @@ Rust does not have the “C-style” `for` loop on purpose. Manually controlling
4242
each element of the loop is complicated and error prone, even for experienced C
4343
developers.
4444

45-
# Loopcounter
45+
# Enumerate
4646

4747
When you need to keep track of how many times you already looped, you can use the `.enumerate()` function.
4848

49-
#### On ranges:
49+
## On ranges:
5050

5151
```rust
5252
for (i,j) in (5..10).enumerate() {
5353
println!("i = {} and j = {}", i, j);
5454
}
5555
```
56+
5657
Outputs:
57-
```
58+
59+
```rust
5860
i = 0 and j = 5
5961
i = 1 and j = 6
6062
i = 2 and j = 7
6163
i = 3 and j = 8
6264
i = 4 and j = 9
6365
```
66+
6467
Don't forget to add the parentheses around the range.
6568

66-
#### On iterators:
69+
## On iterators:
70+
6771
```rust
6872
for (linenumber, line) in lines.enumerate() {
6973
println!("{}: {}", linenumber, line);
7074
}
7175
```
76+
7277
Outputs:
73-
```
78+
79+
```rust
7480
0: Content of line one
7581
1: Content of line two
7682
2: Content of line tree

0 commit comments

Comments
 (0)