In short I have code like this. I know its bad style but have given it a lot of thought and alternatives are worse. What should I say in a comment and where should I put it?
while(1)
{
if(x+y == z)//some comparison
{
…//do something
}
else
{
break;
}
}
Assuming that there is more code involved, so the obvious
is not possible, you could use an additional variable to flag the loop status.
It offers more possibilities, esp. if deeper nesting is involved, since
break;will only leave the innermost loop. Of course you should use a more exact naming for the condition instead of a genericdo_loop, e.g.coords_are_equal.If all alternatives are worse, including this, then just comment it as it is: “All alternatives are found to be worse than this.”