Answer the question
In order to leave comments, you need to log in
Which option is best?
if(a == 3) CallMe();
if(b == 4)
{
CallMe();
Giveme();
}
if(a == 3 || b == 4) CallMe();
if(b == 4) Giveme();
for(var i = 0, j = GetPool(); i <= j; i++)
{
CallFuncTo(i);
}
for(var i = GetPool(); i >= 0; i--)
{
CallFuncTo(i);
}
Answer the question
In order to leave comments, you need to log in
What do you think reads better?
for the first example - the second option as more readable. Let the condition be better duplicated than the action on this condition.
On the second - as it is more convenient to you and if the logic allows a reverse of the order.
For the first block:
switch( b )
{
case 4:
GiveMe();
case 3:
CallMe();
break;
};
class A
{
public:
inline size_t begin()
{
printf( "begin();\n" );
return 0;
};
inline size_t end()
{
printf( "end();\n" );
return 10;
};
};
A cont;
for( size_t iter = cont.begin(); cont.end() > iter; ++iter )
{
printf( "%d\n", iter );
};
In the first case, the options are not equivalent. With a=3, b=4, in the first variant CallMe() will be called twice, and in the second - only once.
The first option is written optimally. To make it behave like the second option (with one call to CallMe()), just insert else:
if(a == 3) CallMe();
else if(b == 4) {
CallMe();
Giveme();
}
bool cond1=(sin(x)>=sin(y));
if(cond1 || cos(x)<cos(y)) Draw(tan(x),tan(y));
if(cond1) CloseLine();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question