-
Notifications
You must be signed in to change notification settings - Fork 13k
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
add documentation for the while keyword #60761
Conversation
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
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.
Looks pretty good to me, in a similar style to for
. Great!
Had some thoughts, left them in review comments.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
while keyword is used to define while loops in rust. Fixes rust-lang#60736.
// | ||
/// while loop | ||
/// | ||
/// `while` is used to define while loops in Rust. It runs the code inside it |
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.
Please write this in a way that is not a tautology ("the while keyword is used to define a while loop"). It is true but not meaningful.
/// | ||
/// ```rust | ||
/// let mut i = 0; | ||
/// while i > 10 { |
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.
0 is not > 10 so this loop would never run -- seems unintentional.
/// while loop | ||
/// | ||
/// `while` is used to define while loops in Rust. It runs the code inside it | ||
/// until the condition in the while loop becomes False or there the code uses |
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.
Capitalization: false is a lowercase noun. This looks like muscle memory from Python. ;)
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.
Probably should also use an inline code block (back ticks) around false
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.
"until the condition becomes false" is meaningful English without backticks. I think adding backticks would detract in this case.
/// | ||
/// `while` is used to define while loops in Rust. It runs the code inside it | ||
/// until the condition in the while loop becomes False or there the code uses | ||
/// `break`. |
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.
until [...] there the code uses
break
.
This "until there" part of the sentence sounds wrong to me. Not clear what "there" is referring to.
/// i += 1; | ||
/// } | ||
/// ``` | ||
/// |
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 page should cover while let
as well.
/// let mut i = 0; | ||
/// while i > 10 { | ||
/// println!("i is {}", i); | ||
/// i += 1; |
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.
Please come up with a different example where while
is the best solution. The point of example code is usually not showing how to write something. The point is showing why you would want to write the thing. This code shows a while loop but if you were solving the problem that this code is solving then you would not want to use a while loop. That makes the example not compelling.
@Pulkit07 any progress so far? Are you having troubles? Do you need any help? |
Hey, sorry for long silence. I have been mostly busy with work, so no progress. Feel free to close this PR or assign the issue to someone else. Thanks! |
As long as you don't say, that you will surrender on this issue, it's yours. It's not critical, so take your time. |
ping from triage @Pulkit07 |
Document `while` keyword This is a rework of rust-lang#60761. Closes rust-lang#60736 r? @dtolnay
Document `while` keyword This is a rework of rust-lang#60761. Closes rust-lang#60736 r? @dtolnay
while keyword is used to define while loops in rust.
Fixes #60736.