Hacker News new | ask | show | jobs
by SilasX 2144 days ago
>I mean how on earth does the word "for" convey a loop?

I don't know about a loop per se, but it's used in plain language when you want the same thing to be done to every element in a set. "Clean this item and put it away. Then do that for every other piece of cooking equipment."

It was actually originally borrowed from its cognate für in German:

>>The name for-loop comes from the English word for, which is used as the keyword in many programming languages to introduce a for-loop. The term in English dates to ALGOL 58 and was popularized in the influential later ALGOL 60; it is the direct translation of the earlier German für, used in Superplan (1949–1951) by Heinz Rutishauser, who also was involved in defining ALGOL 58 and ALGOL 60.

https://en.wikipedia.org/wiki/For_loop

1 comments

> "Clean this item and put it away. Then do that for every other piece of cooking equipment."

Without the "do" it's nonsensical. And that was exactly my point.

I think there's an argument that "do" is just a placeholder for the body of the loop, i.e. "clean this item and put it away". If you flip the order that the body and the iteration are expressed so that it reflects what most programming languages use for syntax, it would be "for each piece of cooking equipment, clean it and put it away". There's no "do" here, nor is it needed.
There you need the word "each" to convey that it's a loop.

I'd certainly agree that "for each" is much better than "for" alone.

That was just one way of phrasing it. You could just as easily put it as, "For every piece of cooking equipment, clean it and put it away."
There you need the word "every" to convey that it's a loop.

I'd certainly agree that "for each" is much better than "for" alone.

"Do your homework" doesn't imply a loop either. Nor does "This could take a while"

It should not be a shock that the english language doesn't naturally have a single word that can express both a condition/duration as well as a command without any other helper words.

Do is superfluous. Everything in an imperative program is a request to do something.

> "Do your homework" doesn't imply a loop either.

But "for these subjects, do your home work" does.

> Nor does "This could take a while"

I never claimed that "while" alone is any better.

> It should not be a shock that the english language doesn't naturally have a single word that can express both a condition/duration as well as a command without any other helper words.

I never asked for a magic word. To the contrary, I was lamenting the lost of the helper word "do", making the "for" alone nonsensical.

> Do is superfluous. Everything in an imperative program is a request to do something.

I disagree. I think "for...do" makes things much clearer than "for" alone.