News for hackers. Stuff that matters.
Re:Source code for Quake 2 rerelease by andybak on Friday August 11, 2023 @05:24AM (#37086717)
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.

Re:Source code for Quake 2 rerelease by augustk on Friday August 11, 2023 @06:21AM (#37087038)
One 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.
Re:Source code for Quake 2 rerelease by rerx on Friday August 11, 2023 @08:11AM (#37087782)
Agreed. I think it's also a little easier to understand what's going on when stepping through the code in a debugger.
Re:Source code for Quake 2 rerelease by another2another on Friday August 11, 2023 @09:02AM (#37088222)
For 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.