Skip to content
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

Foreach '' in sequence from '' to '' with step '' should support negative steps #964

Closed
matteo-cristino opened this issue Nov 15, 2024 · 1 comment · Fixed by #996
Closed
Labels

Comments

@matteo-cristino
Copy link
Collaborator

For example to reverse a list in zencode now you have to do

Given I have a 'number array' named 'list'
Given I have a 'number' named '0'
Given I have a 'number' named '1'

When I create the 'number array' named 'res'

# limit of iteration
When I create the size of 'list'
and I create the result of 'size' - '1'
and I rename 'result' to 'limit'

Foreach 'i' in sequence from '0' to 'limit' with step '1'
    When I create the result of 'size' - 'i'
    and I create the copy of element 'result' from array 'list'
    and I move 'copy' in 'res'
    and I remove 'result'
EndForeach

Then print 'res'

while with negative steps you could do

Given I have a 'number array' named 'list'
Given I have a 'number' named '1'
Given I have a 'number' named '-1'

When I create the 'number array' named 'res'

# limit of iteration
When I create the size of 'list'

Foreach 'i' in sequence from 'size' to '1' with step '-1'
    and I create the copy of element 'result' from array 'list'
    and I move 'copy' in 'res'
EndForeach

Then print 'res'

making it easier to read

@matteo-cristino
Copy link
Collaborator Author

Moreover since Foreach '' in sequence from '' to '' with step '' includes the extremes (from and to), it should works fine when they are equal, e.g. Foreach 'i' in sequence from '2' to '2' with step '1' should run one time the foreach body with i equal to 2

@matteo-cristino matteo-cristino linked a pull request Jan 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant