logoalt Hacker News

bigfishrunningtoday at 1:52 PM3 repliesview on HN

Which is funny, because whenever I encounter a language for which `for` *doesn't* work this way it feels antiquated. I do however wish another keyword was used in many cases, becuase `for` in C and Go is so much different then `for` in Rust or Python. I think the higher-level case (Rust and Python) should really use a word like `foreach` or maybe something compeletely different like `itr`, although I get that they want to "look" more like C


Replies

adrian_btoday at 3:54 PM

Iterators and the loops of the form "forall X in A do ..." have been invented simultaneously with the appearance of the first version of the language C (i.e. around 1974), in the languages Alphard and CLU.

From Alphard and CLU, loops of this form have passed into one of the versions of the language Algol 68 (1977), and from there into the UNIX Bourne shell (1979), which inherited a few Algol 68 syntax features (because its author had worked at writing Algol 68 compilers).

Iterators and "forall" loops have begun to spread into mainstream programming languages, e.g. into C++, only a couple of decades after their invention.

b40d-48b2-979etoday at 3:33 PM

This is what PowerShell does, it has both the archaic `for` style with a newer iterator-like `foreach`.

rbanffytoday at 2:27 PM

I would say Python really wants to look as much not-C as it can. In this case it's not the word "for" but the "for x in" construct.