Anonymous user
Loops/Foreach: Difference between revisions
→{{header|AWK}}: length() does not work for arrays
m (→{{header|C++}}: no <iterator_concepts> in C++11) |
(→{{header|AWK}}: length() does not work for arrays) |
||
Line 234:
}
}</lang>
If elements must be returned in some order, keys must be generated in that order
In the example above the array is filled through the split function,
<lang awk>for(i=1; i <= length(strs); i++) {▼
which uses indexes from 1.
So to iterate over the array's elements in the ''right'' order,
a normal loop can be used:
<lang awk>
n = split("Mary had a little lamb", strs, " ")
print strs[i]
}</lang>
Note that in awk, foreach loops can only be performed against an associative container.
It is not possible to loop against an explicit list, so the following will not work:
<lang awk># This will not work
|