Is else while
without intervening braces considered "safe" maintenance wise?
Writing if-else
code without braces like below...
if (blah)
foo();
else
bar();
...carries a risk because the lack of braces make it very easy to change the meaning of the code inadvertently.
However, is below also risky?
if (blah)
{
...
}
else while (!bloop())
{
bar();
}
Or is else while
without intervening braces considered "safe"?
else while
looks icky. I'd useelse { while (condition) { ... } }
.if
is only evaluated once, butwhile
denotes a loop, so connecting both gives me a unsubstantiated feeling that theif
is part of the loop... somehow...else
clause you want to do thewhile
and do something more? Just use braces, please.