-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Propose replacing the loop
keyword with while true
.
#429
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
Conversation
The only argument I have against this is based around a theoretical future feature that I want: valued break expressions. That is, |
@mcpherrinm why can't you just do something like this? let foo = { let val; while true { if let Some(bar) = baz() { val = bar; break } }; val }; Edit: Ah, I see, 'possibly uninitialized'. |
Whilst I'm sympathetic to the motivation, the idea of treating |
I share pretty much the same viewpoint as @nick29581, this seems nice on the surface but really ends up bringing a lot of special casing and magic. |
@nick29581: We already have a concept of expressions valid in constant expressions. It could be reused to check this without surprises based on LLVM changes. |
@mcpherrinm See #352, which proposes |
@nick29581, I totally agree that only recognizing literal The goal is to get @reem, it is special casing and magic for now, agreed. But isn't that exactly what the |
Whilst it is kind of a wart, I feel we haven't actually got much criticism for the |
Am I the only one who actually likes the loop keyword? It seems so much nicer than saying |
@gankro I prefer it to |
I also agree with @gankro. I also reach for loop much more often than while, since it's usually easier to just loop forever and break when necessary. |
I also prefer 'loop'. I don't see encoding an explicitly infinite loop as a |
-1. |
+1. one less thing to learn coming from elsewhere. (more tangentially, I do actually like go's approach here too, learn one versatile thing and it handles several cases, but I know the full c-like for is a whole other argument. let x=for init;cond;inc{ ...find something... } else{... not found..} would be great IMO.. really leverage the expression syntax and avoid excessive nesting ) |
-1 There are always going to be infinite loops that aren't recognized by the compiler as such – having "magic true" would be ugly and/or complicate the language.
|
I agree with @jkleint in that But I also think, at least in my daily code, If I can imagine one scenario that makes |
@barosl assignment is an expression but it always evaluates to |
@barosl You can do that, but it's not very pretty: let mut line;
while { line = get_next_line(); line != "" } {
// stuff...
} |
We discussed this at this week's triage meeting and there was no appetite for removing |
This is one way we could remove the
loop
keyword from the language before Rust 1.0. It's straightforward and allows us to refine the implementation over time.