-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Loop x times #2792
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
Comments
Whats wrong with for _ in 0..15 {
println!("{}", count);
} |
@KrishnaSannasi
These have different semantic meanings. |
Ok, how often do you actually need to repeat a thing a fixed number of times? I don't see the point of this extensions, especially when Is there precedence for this sort of loop in other languages? I can't think of any of the top of my head. Extending What values can you put in Finally, there is the concern of how to handle Right now, you can do this. assert_eq!(1, loop { break 1 }); I would expect Are there any parsing ambiguities with this? For example loop { return } { } could parse as loop $count { } // where $count = { return 10 } or loop { return } // normal infinite loop that is terminated by a return
{ } // unreachable block |
What you describe falls in the first family of constructs and I suggest you simply add macro for it or just an for _ in times(3) {
} Or, times(3, || {
}); |
It seems unlikely that we would support this given that we also closed #2617. There also doesn't seem to be any strong support or motivation. Closing therefore. |
It would be nice to be able to do this:
would loop 15 times.
The text was updated successfully, but these errors were encountered: