-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Rustdoc: Add loopcounter (enumerate) section to the for-loop chapter #25925
Conversation
Sometimes loop counters are useful and we should show new users how it is achieved in Rust.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -41,3 +41,38 @@ so our loop will print `0` through `9`, not `10`. | |||
Rust does not have the “C-style” `for` loop on purpose. Manually controlling | |||
each element of the loop is complicated and error prone, even for experienced C | |||
developers. | |||
|
|||
# Loopcounter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer "Enumerate"
Thanks @azerupi ! I'm interested in adding this, but there's a number of small formatting things :) |
Hi @steveklabnik |
Outputs: | ||
|
||
```rust | ||
i = 0 and j = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like Rust source code, you should probably just mark it as text
. (Same for the output listing below.)
@azerupi, I'm pretty sure @steveklabnik just meant adding empty lines above and below code blocks and headlines. I don't think he meant marking the output code blocks as |
@killercup Sure, I also found it was a bit weird to format them as rust code but I thought that it was what @steveklabnik was asking, I probably misunderstood :) Anyways, I changed it. Let me know if there are still things to change. |
Looks great! Thanks so much. |
@bors: r+ rollup |
📌 Commit 90057c2 has been approved by |
⌛ Testing commit 90057c2 with merge 5b138f1... |
💔 Test failed - auto-mac-32-opt |
@bors retry |
@bors: retry- ah this doesn't look spurious:
|
@bors: r- |
## On iterators: | ||
|
||
```rust | ||
for (linenumber, line) in lines.enumerate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integration tests correctly reported that lines
is undefined. It would be okay if you added something like this:
# let lines = "hello\nworld".lines();
The #
at the start will be removed before compiling this code but it will tell rustdoc to hide the line from the rendered output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing :)
I updated the code, it should now pass the integration test (I think) :) |
Could someone try again? :) @steveklabnik @gankro @alexcrichton |
@bors: r+ rollup |
📌 Commit c4f42a1 has been approved by |
Hi I added a little section in the for loops about the `enumerate()` function. I think it's useful for beginners to know this function and how you can use it. I used the title loopcounter, but it's probably not the best word to describe it. So let me know if there is a better word :)
Hi
I added a little section in the for loops about the
enumerate()
function.I think it's useful for beginners to know this function and how you can use it.
I used the title loopcounter, but it's probably not the best word to describe it. So let me know if there is a better word :)