Re: [Phix] Language Feature Request: For Each
- Posted by _tom (admin) Dec 13, 2021
- 1170 views
euphoric said...
_tom said...
I guess it's really just syntactic sugar.
sequence s = {1,2,3,4,5} integer i = length(s) for x=1 to i do ?s[x] end for -- vs sequence s = {1,2,3,4,5} each i in s do ?i end each -- each without specifying iterating variable type is default object sequence s = {1,2,3,4,5} each integer i in s do ?i end each
Each one produces the exact same output.
- yes, it is sugar
- yes, it avoids standard boiler plate
your observation shows that a novice would recognize the "each" and "for" statements as being related
be well