25 ms·
Seriously?
by symlinkk 3y ago
Seriously?
- zabzonk 3y agoyep - i am not saying there are no cases for using it, but use of it is always worth looking at.
- CamperBob2 3y agoSame whenever I see a do...while loop. Nothing wrong with a do...while loop, but I've learned to look twice when crossing that particular street. Most loops that don't have bugs tend to support zero iterations seamlessly and inherently.
- dllthomas 3y agoIf you squint, aren't those the same case?
- zabzonk 3y agoum, a do...while always does something at least once - a for-loop not.
- dllthomas 3y agoI was trying to say that the difference between a for loop with < and a for loop with <= is roughly the same as the difference between a while loop and a do-while loop, and to whatever degree that's true they might be due suspicion for the same reason.
- jonhohle 3y agoI 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.
- dllthomas 3y agozabzonk 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.