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:
8 for (x = 0; x < 10; x++) {
13 Instead, it looks like this:
17 println!("{}", x); // x: i32
21 In slightly more abstract terms,
24 for var in expression {
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.
35 [iterator]: iterators.html
37 In our example, `0..10` is an expression that takes a start and an end position,
38 and gives an iterator over those values. The upper bound is exclusive, though,
39 so our loop will print `0` through `9`, not `10`.
41 Rust does not have the “C-style” `for` loop on purpose. Manually controlling
42 each element of the loop is complicated and error prone, even for experienced C