You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inclusive ranges are especially useful if you want to iterate over every possible value in a range. Currently the iteration in Noir is like in Rust 1.0 through 1.25 versions. If you want inclusion of the last element, you need to add one to your end value like:
fn main() {
for i in 0..(26 + 1) {
println!("{}", i);
}
}
Happy Case
In Rust >=1.26 versions, you can now create an inclusive range and it will be very beneficial to add this syntactic sugar to Noir as well.
Example:
fn main() {
for i in 0..=26 {
println!("{}", i);
}
}
Project Impact
Nice-to-have
Would you like to submit a PR for this Issue?
None
The text was updated successfully, but these errors were encountered:
# Description
## Problem\*
Resolves#6171
## Summary\*
Adds support for inclusive for syntax, e.g. `for i in 0..=10`.
## Additional Context
- Added a `ForBounds` struct to handle the desugaring of `start..=end`
into `start..end+1`.
- `ForBounds` has an `inclusive` flag; I thought about adding a
`ForRange::RangeInclusive` similar to `std::ops::RangeInclusive` in
Rust, but then I thought `for` loops will not have the other variants
like `..end`, `start..` and `..`, which wouldn't have two separate
expressions, and the flag is simpler.
- Transforming an inclusive range to Hir and back makes it
non-inclusive, but I think that's fine because the block created by
`ForRange::into_for` to iterate over the array is not turned back
either.
## Documentation\*
Check one:
- [ ] No documentation needed.
- [x] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.
# PR Checklist\*
- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
Problem
Inclusive ranges are especially useful if you want to iterate over every possible value in a range. Currently the iteration in Noir is like in Rust 1.0 through 1.25 versions. If you want inclusion of the last element, you need to add one to your end value like:
Happy Case
In Rust >=1.26 versions, you can now create an inclusive range and it will be very beneficial to add this syntactic sugar to Noir as well.
Example:
Project Impact
Nice-to-have
Would you like to submit a PR for this Issue?
None
The text was updated successfully, but these errors were encountered: