Skip to content

Commit 8d35fc6

Browse files
committed
copyediting: for loops
1 parent b577bee commit 8d35fc6

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/doc/trpl/for-loops.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
% for Loops
22

3-
The `for` loop is used to loop a particular number of times. Rust's `for` loops
4-
work a bit differently than in other systems languages, however. Rust's `for`
5-
loop doesn't look like this "C-style" `for` loop:
3+
The `for` loop is used to loop a particular number of times. Rusts `for` loops
4+
work a bit differently than in other systems languages, however. Rusts `for`
5+
loop doesnt look like this C-style `for` loop:
66

7-
```{c}
7+
```c
88
for (x = 0; x < 10; x++) {
99
printf( "%d\n", x );
1010
}
1111
```
1212

1313
Instead, it looks like this:
1414

15-
```{rust}
15+
```rust
1616
for x in 0..10 {
1717
println!("{}", x); // x: i32
1818
}
1919
```
2020

2121
In slightly more abstract terms,
2222

23-
```{ignore}
23+
```ignore
2424
for var in expression {
2525
code
2626
}
2727
```
2828

29-
The expression is an iterator, which we will discuss in more depth later in the
30-
guide. The iterator gives back a series of elements. Each element is one
31-
iteration of the loop. That value is then bound to the name `var`, which is
32-
valid for the loop body. Once the body is over, the next value is fetched from
33-
the iterator, and we loop another time. When there are no more values, the
34-
`for` loop is over.
29+
The expression is an [iterator][iterator]. The iterator gives back a series of
30+
elements. Each element is one iteration of the loop. That value is then bound
31+
to the name `var`, which is valid for the loop body. Once the body is over, the
32+
next value is fetched from the iterator, and we loop another time. When there
33+
are no more values, the `for` loop is over.
34+
35+
[iterator]: iterators.html
3536

3637
In our example, `0..10` is an expression that takes a start and an end position,
3738
and gives an iterator over those values. The upper bound is exclusive, though,
3839
so our loop will print `0` through `9`, not `10`.
3940

40-
Rust does not have the "C-style" `for` loop on purpose. Manually controlling
41+
Rust does not have the C-style `for` loop on purpose. Manually controlling
4142
each element of the loop is complicated and error prone, even for experienced C
4243
developers.
43-
44-
We'll talk more about `for` when we cover *iterators*, later in the Guide.

0 commit comments

Comments
 (0)