In no situation do we really need the do ... while
except to make the code more elegant and better express the intention that the execution of the block should take place at least once before deciding whether it will be repeated or not.
It is always possible to do the same with just the while
. Of course the code may have to be a little larger and less elegant, having to do something artificial to ensure that the first execution of the condition is true.
This may not always be so easy to do because it may involve checking something you own side effects, in some cases until you have something similar to Schrödinger’s Cat Paradox, where to access a value, you change the value. You can give different results depending on the moment. You can solve this, but you have to know how to do it, remember to do it and increase the code. In general the solution is a flag or a cached value, which can become complex when access changes the value (although this should not happen in good codes).
Of course, it can help you not to make mistakes, too. You may be mistaken to ensure that the first pass is true and in some unusual case it is false, or you may change something in the code that ends up changing the real warranty situation without the programmer noticing.
It gives more legibility and maintainability as any construction that helps give more semantics to the purpose.
Please read this excellent reply: http://answall.com/a/81431
– Caffé
In Visual Basic, the
Do...While
is calledDo...Until
:)– CypherPotato