Re: foreach
- Posted by jeremy (admin) Jul 24, 2008
- 1024 views
I like the ability to modify the variable:
s = {1,2,3} foreach x in s do x *= 2 end foreach -- s is now {2, 4, 6}
I think a simple foreach added to 4.0 would be a good thing. We can add in parameters in 4.1 such as reversed and multiple item iteration. The same with the above variable modification. As for the changing list size, I would make it act like a for, i.e. from x to y, thus foreach is equivilent to:
s = {1, 2, 3} foreach x in s do ? x end foreach -- Same as: for i = 1 to length(s) do x = s[i] ? x end for
To add that would be pretty simple, effective for 90% of all uses and does not mean we cannot add on the other fancies in 4.1, yet would be easy to implement, would reseve the keyword in 4.0, add greater functionality to Euphoria brining it closer to syntax capabilities of our competitors and at what cost? I do not see any except a bit of time to implement.
Jeremy