I find it most useful in action chains, which often include error detection, etc.
if ((rc = first_check(arg1, arg2)) != 0) { report error based on rc } else if ((rc = second_check(arg2, arg3)) != 0) { report error based on new rc } else if ((rc = third_check(arg3, arg4)) != 0) { report error based on new rc } else { do what you really wanted to do }
An alternative (without using the assignment in the condition) is:
rc = first_check(arg1, arg2); if (rc != 0) { report error based on rc } else { rc = second_check(arg2, arg3); if (rc != 0) { report error based on new rc } else { rc = third_check(arg3, arg4); if (rc != 0) { report error based on new rc } else { do what you really wanted to do } } }
With long-term error checking, the alternative may exit the RHS page, while the conditional version does not.
Jonathan Leffler Sep 30 '08 at 5:59 2008-09-30 05:59
source share