Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree with parent. do-while communicates that a thing will always execute once, and maybe more, and a while or for loop (even in the higher level for-each/for-in case) may never execute at all.

Being able to choose the right control structure (and data structures) can provide additional information to the correctness of the code than arbitrary choices which may perform the same function. Choosing the Most expressive options may or may not conflict with performance, in which case, comments are helpful to describe why more obvious approaches weren’t taken.



zabzonk is obviously correct about the behavior of the control structures - that's not something I ever meant to disagree about.

The thread had had one poster state they find <= suspicious in a for loop, and another about any do-while loop. I don't think these are literally the same thing (hence "if you squint") but I think they share a meaningful similarity of adding an extra pass through the loop compared to the other form and I thought that was interesting.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: