Question
Do all programming languages have boolean short-circuit evaluation?
In the PHP code
if(a() && b())
when the first operand evaluates to false
, b()
will not be evaluated.
Similarly, in
if (a() || b())
when the first operand evaluates to true
, b()
will not be evaluated..
Is this true for all languages, like Java, C#, etc?
This is the test code we used.
<?php
function a(){
echo 'a';
return false;
}
function b(){
echo 'b';
return true;
}
if(a() && b()){
echo 'c';
}
?>