Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style of for loops enumeration example is unclear Ch. 4.6 of The Book. #34624

Closed
GoudaOnBeamPro opened this issue Jul 3, 2016 · 3 comments · Fixed by #34880
Closed

Style of for loops enumeration example is unclear Ch. 4.6 of The Book. #34624

GoudaOnBeamPro opened this issue Jul 3, 2016 · 3 comments · Fixed by #34880

Comments

@GoudaOnBeamPro
Copy link

The example is as follows:

for (i,j) in (5..10).enumerate() {
    println!("i = {} and j = {}", i, j);
}

The first tuple does not have a space between the comma and the j -> (i,j)
Is this correct?

@xitep
Copy link

xitep commented Jul 3, 2016

apart from the reported issue; in this example, it would be nice to name j something like element or just v (for "value") to make clear that i is the enumerated index. i and j are often used for index variables. maybe even falling back to longer names like "index" and "value" would be better.

in the mentioned book chapter, the example on using lines.enumerate() that follows the reported one, is very clear and self-explanatory.

Manishearth added a commit to Manishearth/rust that referenced this issue Jul 4, 2016
Fix spacing in for loop enumeration example

Add a space between the comma and j in (i, j) to make it look nice.

This addresses my recent issue rust-lang#34624.

😀
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jul 5, 2016
Fix spacing in for loop enumeration example

Add a space between the comma and j in (i, j) to make it look nice.

This addresses my recent issue rust-lang#34624.

😀
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jul 5, 2016
Fix spacing in for loop enumeration example

Add a space between the comma and j in (i, j) to make it look nice.

This addresses my recent issue rust-lang#34624.

😀
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jul 6, 2016
Fix spacing in for loop enumeration example

Add a space between the comma and j in (i, j) to make it look nice.

This addresses my recent issue rust-lang#34624.

😀
@Blaisorblade
Copy link

The original issue appears addressed in #34625, which was merged (though it's not yet reflected in the manual, https://doc.rust-lang.org/book/loops.html).

There's still the comment of @xitep to address, and I agree with him.

@steveklabnik
Copy link
Member

(though it's not yet reflected in the manual, https://doc.rust-lang.org/book/loops.html).

Everything lands on nightly, then makes its way through the trains. So you can see it https://doc.rust-lang.org/nightly/book/loops.html , and it'll make it into 1.12's docs.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 21, 2016
Make .enumerate() example self-explanatory

Should resolve rust-lang#34624
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants