Why do we use do while loop when there are better loops available?

I didn't find any practical use of do-while loop. As a studied we don't have control over the do-while loop when it executes for the first time and everything which can be done with do-while loop, can be don with while or for loop (assuming).

My Question is: Is there any situation where we use a do-while loop, or any particular situation where it gives more reliable results as compared to for and while loops?

Jon Skeet
people
quotationmark

do/while is precisely suitable when you always want to execute at least once, but you want to check whether or not to keep going at the end of the loop instead of at the start.

You can easily emulate it with a while loop, but sometimes the code becomes less clear that way. All three loop types can be emulated with each other, with more or less mess - but as all three are available, you should just pick the most appropriate loop for the job in hand.

I personally use both while loops and do/while loops less often than for loops, but sometimes a do/while is the most readable option.

people

See more on this question at Stackoverflow