if (e1) return e2; [else] s1;

Emuleomo emuleomo at paul.rutgers.edu
Thu Mar 29 02:59:20 AEST 1990


In article <10624 at alice.UUCP>, ark at alice.UUCP (Andrew Koenig) writes:
> Some people take the view that except at the end of a function,
> `return' is just a funny way of spelling `goto.'
> -- 
> 				--Andrew Koenig
> 				  ark at europa.att.com

Yeah, but this <goto> can be really beneficial if used properly.
Consider

main()
{
	if (<condition>) return(FAILURE);

	a +=b;
	etc...
	etc...
	etc...
	return(SUCCESS);
}

AND

main()
{
	if (<condition>)
		status_code = FAILURE;
	else
	{
		a +=b;
		etc...
		etc...
		etc...
		status_code = SUCCESS;
	}
	return(status_code);
}

Somehow, I think the former is becomes easier to comprehend as the size of
the code "inside" the else clause get larger.

--Emuleomo O.O. (emuleomo at yes.rutgers.edu)
-- 
*Nothing* is hard.   If it looks hard, you are looking at it the hard way!



More information about the Comp.lang.c mailing list