Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site 3comvax.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxr!ulysses!allegra!oliveb!3comvax!mikes From: mikes@3comvax.UUCP (Mike Shannon) Newsgroups: net.lang.c Subject: Re: C style Message-ID: <259@3comvax.UUCP> Date: Mon, 28-Oct-85 20:44:26 EST Article-I.D.: 3comvax.259 Posted: Mon Oct 28 20:44:26 1985 Date-Received: Wed, 30-Oct-85 07:01:27 EST References: <1556@brl-tgr> <2600023@ccvaxa> Organization: 3Com Corp; Mountain View, CA Lines: 63 Sorry Scott, I don't buy it. Your example isn't good enough: Scott's example: > checkreturn = OK; > for (i=0; i<100 && checkreturn==OK; i++) { > checkreturn = function1(x); > if (checkreturn == OK) { > checkreturn = function2(x); > if (checkreturn == OK) { > checkreturn = function3(x); > if (checkreturn == OK) { > checkreturn = function4(x); > if (checkreturn == OK) { > checkreturn = function5(x); > if (checkreturn == OK) { > result[i] = function6(x); > } > else { > result[i] = 0; > } > } > } > } > } > } > ------- Scott's example done the RIGHT (i.e. my :-)) way: for(i = 0; i < 100; i++) { if(f1(x) == OK && f2(x) == OK && f3(x) == OK && f4(x) == OK && f5(x) == OK ) { result[i] = 0; } else { result[i] = function6(x); } } -------- In general, I don't like humongous if statements like the above, but this one is pretty easy to read. I didn't do anything with checkreturn, because Scott's code didn't use it for anything, either. In the more usual case where you need to take different error actions depending on several successive function calls, I venture to state that It Should Be Done This Way: if(f1() == ERROR) { take some sort of error action. } else if(f2() == ERROR) { fix up any side effects of f1,side effects are bad practice too take some other sort of error action } else if(f3() == ERROR) { fix up side effects of f1 and f2 take another error action } else { collect two hundred dollars, you may pass GO } -- Michael Shannon {ihnp4,hplabs}!oliveb!3comvax!mikes