R
Rajen
Hi all,
I have a code like this.
if(X)
{
return retVal1;
}
if(Y)
{
return retVal2;
}
if(Z)
{
return retVal3;
}
The above if can be written like this
int retVal = 0;
if(X)
{
retVal=retVal1;
}
if( retVal == 0)
{
if( Y)
retVal=retVal2;
}
if( retVal == 0 )
{
if(Z)
retVal=retVal3;
}
return retVal;
which has only one exit point. But it has more If's
How do i Optimize this? Please give me some suggestions.
I have a code like this.
if(X)
{
return retVal1;
}
if(Y)
{
return retVal2;
}
if(Z)
{
return retVal3;
}
The above if can be written like this
int retVal = 0;
if(X)
{
retVal=retVal1;
}
if( retVal == 0)
{
if( Y)
retVal=retVal2;
}
if( retVal == 0 )
{
if(Z)
retVal=retVal3;
}
return retVal;
which has only one exit point. But it has more If's
How do i Optimize this? Please give me some suggestions.