-
Notifications
You must be signed in to change notification settings - Fork 10
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
for loop direction #8
Comments
I was just thinking about this again, and maybe I'm over thinking it and it doesn't need to be this complicated or even need any changing at all... But would an optional |
Good points. I hadn't considered reverse loops. As you say this would be easy if When I read your issue last night I also thought of Explicitly specifying the step immediately signals to the compiler that this is a reverse loop so it will output the appropriate Teal but also it's a nice signal to the reader. I don't think the step needs to be an expression. That could allow for very unreadable code for little gain. I'd suggest we have two forms:
If you do How does that sound? |
Maybe a custom step is useful though? So you could do: But still not |
Yes! Similar to how Python's slice step works. I suspect |
I noticed that
for
loops always expect to increment between thestart
andend
values, only breaking whenvar
equals exactly theend
value (which could be a problem if it somehow skips over it). However if you wanted to loop from a higher value to a lower value (e.g. swap the order offor n in 1:5:
tofor n in 5:1:
) it results in TEAL that will hit an AVM error when evaluated ("cost budget exceeded"), since it never breaks.At first I thought maybe I could quickly modify the
tealish/__init__.py
file to check ifstart
was greater thanend
, then write "-" instead of "+"... And then I realised they don't have to be defined values at all, and may be unkonwn until runtime.Should there be an easy way to define or flip the default direction of a
for
loop without having to write additional logic to work with an incrementing value?The text was updated successfully, but these errors were encountered: