Re: [Phix] Language Feature Request: For Each
- Posted by euphoric (admin) Dec 13, 2021
- 1132 views
_tom said...
- a flaw in the Python model is you do not have access to the index
That's not a flaw; it's by design. This isn't the loop you use if you want the index. (Or use your own index...)
integer c = 1 -- if you want the index, here you go each i in {1,2,3,4,5} ?i c+=1 -- increment the index end each
_tom said...
I find the index handy because sometimes I want to "look ahead" or "look behind" the element currently selected ... therefore I sometimes need the index.
In that case, you would not use each. You would use for. Each is syntactical sugar for a for loop where you don't need the index, just the item at the index.