multiple returns in a routine
yes, for example
int function(){
if(x) return(1);
if(y) return(2);
if(z) return(3);
return(0);
}
compared to below, what is opinion on code size and speed?
it is very easy to have return()'s all over the place, which can lead to confusion - but makes for less planning and ease...
ie, some would say "one entry point and one exit point" - I grew up with this thinking but I am not so sure about it any more ;)
interesting to read peoples thoughts on this too!
int function(){
int retVal=0; //default
if(x) retVal = 1;
else
if(y) retVal = 2;
else
if(z) retVal = 3;
return(retVal);
}
can one have more than one retrun statement in a routine? the return statmets are nested in conditional "different scope" blocks.
thanks