News for hackers. Stuff that matters.
Re:Avoid Else, Return Early (2013) by ajuc on Monday March 26, 2018 @11:01AM (#16679395)
You want to write "cat" equivalent. How do you do the loop?

I think for loops should be limited to iteration over collections, or repeating sth known number of times.

There are cases when you need to decide if you want to continue iteration on the fly, and while loop is the perfect tool for that. Also while loop is arguably less error-prone than for loop: can't swap clauses because there's just one, can't write "," instead of ";" by mistake.

There are no comments on this comment yet.