Hacker News new | ask | show | jobs
by wwwwewwww 2020 days ago
I would love to read something similar about a "for" loop. "if/else" always sounded natural to me, but a "for" to mean a loop never did.
2 comments

I bet it's from maths. "For k in Z, ...". But in programming, imperative is more useful than declarative, so we turned this into "For k from 0 to ...", as it translates directly to telling the computer what to do - and this is the form most programmers ended up being exposed to.
For is also from Algol, replacing "do" from Fortran. I agree it would be interesting to know why the word was chosen, but I think it comes from the mathematical "for all x in Y, x > 5" or whatever other assertion is being made.