Re: [Phix] Language Feature Request: For Each

new topic     » goto parent     » topic index » view thread      » older message » newer message
_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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu