Some languages use short-circuit, and others use full Boolean evaluation (if you know, this is similar to the directive $B
in Pascal).
Explanations:
function A(){
...Do something..
return true;
}
function B(){
...Do something..
return true;
}
if ( A() OR B() ) { .....
In this example the function B()
will never be executed. Since the function A()
returns TRUE, the result of the OR statement is known from the first part without it being necessary to evaluate the second part of the expression.
However with ( A() || B() )
, the second part is always evaluated regardless of the value of the first.
For optimized programming, you should always use OR
which is faster (except for the case when the first part returns false
and second part actually needs to be evaluated).