File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
branches/tmp/src/doc/trpl Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32
32
refs/heads/beta: 62e70d35be3fe532c26a400b499c58a18f18dd3a
33
33
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
34
34
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35
- refs/heads/tmp: 6e2f18ef322c094ed49eee11994fc49c5cacbc2a
35
+ refs/heads/tmp: 151c3d3644c2d8b21465dd8a48ad753539e18c88
36
36
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
37
37
refs/tags/homu-tmp: b77d60adb019bb5de05e884a99f3290ec4694137
38
38
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412
Original file line number Diff line number Diff line change @@ -42,35 +42,41 @@ Rust does not have the “C-style” `for` loop on purpose. Manually controlling
42
42
each element of the loop is complicated and error prone, even for experienced C
43
43
developers.
44
44
45
- # Loopcounter
45
+ # Enumerate
46
46
47
47
When you need to keep track of how many times you already looped, you can use the ` .enumerate() ` function.
48
48
49
- #### On ranges:
49
+ ## On ranges:
50
50
51
51
``` rust
52
52
for (i ,j ) in (5 .. 10 ). enumerate () {
53
53
println! (" i = {} and j = {}" , i , j );
54
54
}
55
55
```
56
+
56
57
Outputs:
57
- ```
58
+
59
+ ``` rust
58
60
i = 0 and j = 5
59
61
i = 1 and j = 6
60
62
i = 2 and j = 7
61
63
i = 3 and j = 8
62
64
i = 4 and j = 9
63
65
```
66
+
64
67
Don't forget to add the parentheses around the range.
65
68
66
- #### On iterators:
69
+ ## On iterators:
70
+
67
71
``` rust
68
72
for (linenumber , line ) in lines . enumerate () {
69
73
println! (" {}: {}" , linenumber , line );
70
74
}
71
75
```
76
+
72
77
Outputs:
73
- ```
78
+
79
+ ``` rust
74
80
0 : Content of line one
75
81
1 : Content of line two
76
82
2 : Content of line tree
You can’t perform that action at this time.
0 commit comments