A
Angus Graham
Hi:
I've recently come across a number of programmers who use the following
type of do/while(false) structure quite often:
do {
if (! CatchFish(pFish)) {
break;
}
if (! CleanFish(pFish)) {
break;
}
if (! CookFish(pFish)) {
break;
}
if (! EatFish(pFish)) {
break;
}
while (false);
delete pFish;
This is effective but seems to me to be bad style. The do/while loop
isn't really a loop at all which is misleading. The same could be
achieved with a boolean flag.
e.g.,
bool bSuccess = CatchFish(pFish);
if (bSuccess) {
bSuccess = CleanFish(pFish);
}
etc.
Exceptions are not being used because we are assuming that the methods
can return false under non-exceptional circumstances.
Any comments on this sort of do/while (false) style?
Angus.
I've recently come across a number of programmers who use the following
type of do/while(false) structure quite often:
do {
if (! CatchFish(pFish)) {
break;
}
if (! CleanFish(pFish)) {
break;
}
if (! CookFish(pFish)) {
break;
}
if (! EatFish(pFish)) {
break;
}
while (false);
delete pFish;
This is effective but seems to me to be bad style. The do/while loop
isn't really a loop at all which is misleading. The same could be
achieved with a boolean flag.
e.g.,
bool bSuccess = CatchFish(pFish);
if (bSuccess) {
bSuccess = CleanFish(pFish);
}
etc.
Exceptions are not being used because we are assuming that the methods
can return false under non-exceptional circumstances.
Any comments on this sort of do/while (false) style?
Angus.