Re: [Phix] Language Feature Request: For Each
- Posted by _tom (admin) Dec 13, 2021
- 1152 views
- ''for'' is a keyword; do not overload
python
- for reference, a Python loop looks like:
for x in mylist: print(x)
this is a clever way to hide the mess created by off-by-one indexing
suggested new feature
- the OE/Phix equivalent could look like
each <item> in <sequence> do <... statements> end each
sample usage
- simulate the existing ''for'' loop
each {i} in {"one","two","three"} do ? i end each
1 2 3
- simulate Python loop
each {i,x} in {"one","two","three"} do ? x end each
"one" "two" "three"
- demonstrate Euphoria thinking
each {i,key,value} in {{"eins","uno"}, {"dwei","duo"}, {"drei","tres"}} do ? key ? value ? "---" end each
"eins" "uno" "---" "dwei" "duo" "---" "drei" "tres" "---"
multiple assignment paradigm
the ''each'' statement implies
{ i, key, value } := { 3, "drei", "tres" } ^ ================= element as a flat sequence | index
be well _tom