Sujet : Re: Loops (was Re: do { quit; } else { })
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 19. Apr 2025, 08:20:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vtvis0$u894$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 18.04.2025 16:34, bart wrote:
On 18/04/2025 14:01, Janis Papanagnou wrote:
>
Sure, many language support newer syntaxes for such things. Even older
languages do such abstractions; e.g. Awk[*]
>
split ("one two three four five", table)
for (i in table)
print i, table[i]
>
(One of many things I like in this very small but powerful language.)
I had to check your claims:
* Awk primarily uses a C-style for loop; using 'for in' is an
alternative (it's not clear if this is specific to gnu-Awk)
The 'in' loop was always available and is also POSIX standard.
My footnote (you stripped it)....
[*] Read it as "GNU Awk", since in that variant (as opposed to standard
Awk) you can control the 'for' iteration order.
...pointed to a non-standard GNU extension how to iterate over Awk's
associative arrays; the standard provides no guarantee about the order
of traversal. GNU Awk allows to iterate in various ways; by index or
by value, in numeric or alphabetic order, ascending or descending.
These options are a very useful extension.
* 'i in table' iterates over /indices/, not values as is more typical of
languages that support 'in'.
Yes. - But see what I wrote about traversal options in GNU Awk.
Janis
[...]