4 ms·
Another option that works very well is this: ret = thing1(...); if (ret == 0) ret = thing2(...); if (ret == 0)
by cryptonector 9y ago
Another option that works very well is this:
ret = thing1(...);
if (ret == 0)
ret = thing2(...);
if (ret == 0)
ret = thing3(...);
if (ret)
<handle failure>;
<common cleanup>;
return ret;
No ever-deepening if/else ladders, and no goto-fails.
Alternatively:
if ((ret = thing1(...))
goto out;
if ((ret = thing2(...))
goto out;
if ((ret = thing3(...))
goto out;
out:
if (ret)
<handle failure>;
<common cleanup>;
return ret;
This has a goto-fail, but only one, so it's Go-like.