What are the differences between writing:
if(condition1 && condition2){
//some code
}
And:
if(condition1){
if(condition2){
//some code
}
}
If there are any, which one is better?
The differences are mainly in readability and maintenance.
Concatenation of 2 logical conditions should usually imply that there is a semantic relation between them.
Another thing to consider is the scoping. The nested if
gives you additional flexibility in this area.
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