Re: [Phix] Language Feature Request: For Each
- Posted by euphoric (admin) Dec 10, 2021
- 1310 views
petelomax said...
euphoric said...
How about a For...Each...End For?
I was thinking
for i, string key in {"one","two","three"} do for i, id in {2,4,6} do for i, object key in {"Hello",3,{1,2,3}} do for i, string key in all_keys do
Why "for i"? (It seems redundant.)
Should simply be:
for string key in {"one","two","three"} do for integer id in {2,4,6} do for object key in {"Hello",3,{1,2,3}} do for string key in all_keys do
"key" takes on the value of, not the pointer to, the element in the sequence it is iterating, so the iterable sequence never gets changed in this.
Javascript's forEach() is definitely interesting, but is a method on a class (it seems), so not analogous to Phix's version (it seems).