What is the advantage of a do-while(false)?

java, loops, while-loop

Solution

Maybe it was done to be able to jump out of the "loop" at any time, e.g:

do
{
    ...
    if (somethingIsWrong) break;
    //more code
    ...
}
while(false);

But as others have said, I wouldn't do it like this.

Problem

When looking through some code that was handled by another employee, I see a lot of code written in: ``` do{ ... }while(false); ``` What advantage (if any) does this provide? Here is more of a skeleton that is happening in the code: ``` try{ do{ // Set some variables for(...) { if(...) break; // Do some more stuff if(...) break; // Do some more stuff } }while(false); }catch(Exception e) { // Exception handling } ``` Update: C++ Version: Are do-while-false loops common?

Original source

Related problems