3 ms·
I think it's debateable which is clearer. Your while condition requires some mental parsing of the booleans whereas the original can be analysed one at a time.
by andybak 3y ago
I think it's debateable which is clearer. Your while condition requires some mental parsing of the booleans whereas the original can be analysed one at a time.
I'd say I prefer the original.
- augustk 3y agoOne nice property with (pure) structured programming is that the statement do { ... } while (p); guarantees that p is false after the loop and this makes it easier to reason about the program. With breaks, however, the loop could be "lying" so to speak.
- rerx 3y agoAgreed. I think it's also a little easier to understand what's going on when stepping through the code in a debugger.
- another2another 3y agoFor me the original is much clearer and is how I normally structure my iterators/do/for loops, since explicitly checking for conditions and using 'continue' when the iterated value is not worth processing makes it nice and clear that everything _after_ these checks is valid and can contain the meat of the processing without more if/else checks. This approach also works fine for c++ and c# code (probably also java too), which I like as it keeps my projects nice and consistent and I can jump between codebases and feel at home. The only thing that I don't like about it is the if() statements not being contained in {}'ies. That always makes me nervous.