Skip to content

Commit 3fd076c

Browse files
Added enumerate function in control flow.md - for loop section (#65)
* Added enumerate function in for loop * Update a10.control-flows.md --------- Co-authored-by: Dumindu Madunuwan <[email protected]>
1 parent d9a841e commit 3fd076c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

content/en/docs/a10.control-flows.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,15 @@ for b in 0..6 {
271271
// Working with arrays/vectors
272272
let group : [&str; 4] = ["Mark", "Larry", "Bill", "Steve"];
273273

274-
for n in 0..group.len() { // group.len() = 4 -> 0..4 👎 check group.len()on each iteration
274+
for n in 0..group.len() { // group.len() = 4 -> 0..4 👎 check group.len() on each iteration
275275
println!("Current Person : {}", group[n]);
276276
}
277277

278278
for person in group.iter() { // 👍 group.iter() turn the array into a simple iterator
279279
println!("Current Person : {}", person);
280280
}
281+
282+
for (index, person) in group.iter().enumerate() { // 💡 group.iter().enumerate() helps to read both the current index (starting from zero) and the value
283+
println!("Person {} : {}", index, person);
284+
}
281285
```

0 commit comments

Comments
 (0)