-
-
Notifications
You must be signed in to change notification settings - Fork 813
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
VIP: allow variable ranges with max bounds #2527
Comments
This probably becomes more relevant with dynamic arrays #1440 |
Might be more interesting to do it like a slice of the dynamic variable itself: for item in slice(self.dynamic_array, self.start, LENGTH):
<loop body>
self.start += LENGTH # So next time we do it, we start ahead of last time |
Yeah often we want access to the |
I like |
Meeting notes: consider iteration over |
and also how it fits in with dynamic arrays #1440 |
Implemented in #3537 |
Simple Summary
Add variable ranges with max bounds, e.g.
for i in range(<var>, bound=100)
Motivation
Right now vyper requires for-loop ranges to be bounded at compile time. However, an extremely common use case is to iterate over some variable counter at runtime. This leads to the common idiom,
This proposal allows a runtime variable counter but also requires a max bound on the range.
Specification
Add a
bound
keyword arg to therange
builtin, and relax the restrictions on the first argument to allow it to be a non-literal variable. For instance, the above example would becomeBackwards Compatibility
None known
Dependencies
References
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: