PDA

View Full Version : order of if conditions and performance?



werehunt
December 26th, 2009, 11:59 AM
whan constructing conditions in if statement i was always looking to put more important ones (which have most chance to broke the condition) at the beginning.

like:
if(a<b && d != z and so on...){

}

but this actually doesnt matter...or does it?

wvxvw
December 26th, 2009, 12:03 PM
Yes, it does, if the first condition fails other aren't executed.

Scott64
December 26th, 2009, 12:31 PM
Yes, it does, if the first condition fails other aren't executed.
Or in the case of ||, if the first is true it doesn't bother testing the rest.