15

I am using do while ONLY on programming exercises. And do not remember a single case I have used it for anything real.

Comments
  • 1
    I used it for retrying HTTP calls but quickly replaced with a framework level construct
  • 1
    Useful when no action is needed. Like do while not eof... won't crash if fed an empty file.
  • 3
    I use "do {...} while 0" quite frequently in multi-line macros. Not only that I can use scope-local variables, it also doesn't fuck up with surrounding if/else.
  • 0
    Can work for recursion 🤷‍♂️ But I feel functions usually do a better job
  • 3
    It's used a lot in randomised algorithms, because the main idea is usually to pick a random value, do some calculation, and then repeat until the condition matches.

    Also do ... while in compiled languages generally results in the fastest runtime and smallest binary size out of all loops, due to the way it translates to machine code.
Add Comment