Search code examples
c++do-whilecontrol-flow

What is the purpose of do {...} while(false)?


I was looking at some code by an individual and noticed he seems to have a pattern in his functions:

<return-type> function(<params>)
{
 <initialization>

 do
 {
   <main code for function>
 }
 while(false);

 <tidy-up & return>
}

It's not bad, more peculiar (the actual code is fairly neat and unsurprising). It's not something I've seen before and I wondered if anyone can think of any logic behind it - background in a different language perhaps?


Solution

  • You can break out of do{...}while(false).