If I need to check multiple conditions, which is the preferred way with respect to performance
if( CND1 && CND2 && CND3 && CND4)
{
}
else
{
}
or
if(CND1)
{
if(CND2)
{
if(CND3)
{
if(CND4)
{
}
else
{
}
}
else
{
}
}
else
{
}
}
}
The performance is the same since it will stop checking the arguments once it has found a false one (short-circuiting), so definitely go with the first one. It's one line compared to like, 10. It also means that your else
will be much easier to handle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With