I was looking at some code by an individual and noticed he seems to have a pattern in his functions:
function()
{
It's simple: Apparently you can jump out of the fake loop at any time using the break
statement. Furthermore, the do
block is a separate scope (which could also be achieved with { ... }
only).
In such a situation, it might be a better idea to use RAII (objects automatically destructing correctly when the function ends). Another similar construct is the use of goto
- yes, I know it's evil, but it can be used to have common cleanup code like so:
function()
{
error:
}
(As an aside: The do-while-false construct is used in Lua to come up for the missing continue
statement.)