Suppose I had an if statement in a method like so:
if ( foo() || bar() ) {
return true;
}
Would both foo()
and bar()
both be processed entirely before assessing whether to execute the code within, or as soon as one condition satisfies the if?
My reason for asking is that my equivalents of the foo()
and bar()
methods are fairly computationally expensive functions, and if foo()
alone satisfied the if conditions I would not want to execute bar()
. As such, my current code is along the lines of:
if ( foo() ) {
return true;
}
if ( bar() ) {
return true;
}
Is this necessary, or would the logical OR separated function behave as a require?