Note - Assume the code is in JAVA
Suppose I have a function -
public boolean Helper(){
boolean a = ...;
boolean b = ...;
boolean c = ...;
boolean d = ...;
return a || b && c || d;
}
I want to understand what are the possible ways in which the expression is actually evaluated. I am not talking about the logic table where we fill up ones and zeroes. For example - To my understanding, if a is true, it won't matter what values the rest of the variables hold.( As there will be short circuit evaluation) Can someone please help me in listing down all such conclusions? This boolean expression is very confusing to me
All you need to know is three things:
Precedence rules. That is evaluated either as
(a || b) && (c || d), or asa || (b && c) || dor as((a || b) && c) || d. A simple matter of searching the web for 'java operators precedence' will get you your answer.Awareness that in java, the doubled up versions of the or and and operator (
||and&&, being used here) 'short circuit'.a && bwill not eval b ifais false, as the result is already known.basic logic tables.
All this stuff is trivially found. I think the homework exercise partly involves you actually looking all this up :)