
Originally Posted by
R3.RyozKidz
so the value in m is 2 and n is 1?
Actually the value of both is 1 since true=1 and false=0 and both of the OR operations take in at least 1 value of "true". However i=2 and j=1 after all 4 lines are executed. That is because of the lazy evaluation that ignores the ++j statement because the || operation already received one value of true, and that's all it needs to output true. You can think of || and && as functions such that
Code:
bool || (bool a, bool b){
if(a == true){
return true;
}
if(b == true){
return true;
}
return false;
}
bool && (bool a, bool b){
if(a == false){
return false;
}
if(b == false){
return false;
}
return true;
}
The code above illustrates exactly the type of lazy evaluation that is done for both the && and || operations. The only thing not represented in the code is that && is evaluated before || in order of operations just like multiplication is evaluated before addition.
-TheSourceOfX
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum