I'm working on code for daylight savings time correction with a 1307 RTC and need to have an if statement check multiple values. Does it matter if you have multiple if comparisons vs nesting if statements? At first blush it seems like the latter would potentially be more efficient, but IIRC, multiple conditions in IF statements are actually performed independently anyway and if the compiler is smart enough to stop the comparisons after one of the conditions is false, it shouldn't matter.
if (x == 1 && y == 2 && z == 3)
-vs-
if (x == 1){
if (y == 2){
if (z == 3){
}
}
}
In that context I don't think it matters which is fastest. I'd move on and use whichever method makes your code more readable (which IMO is the first version).
Anyway I wouldn't be surprised if the resultant code was the same given the quality of optimising compilers.
if the compiler is smart enough to stop the comparisons after one of the conditions is false,
Actually, it's not a choice for the compiler designer, it's a C language requirement, which has bitten many programmers who expected every clause in an if to be evaluated, introducing subtle bugs into their code.