2 Replies Latest reply on Oct 30, 2012 8:26 PM by EJP

# Regular expression evaluation with logical operator

Hi All,

I am bit confuse with expression evaluation with logical operator. I am trying to understand below expression.

-----
eXa.getTrue() && eXa.getFalse() || eXa.getFalse() && eXa.getTrue() || eXa.getFalse() comes as false and True Count: 1 False Count: 3

As per understanding it should be true with True Count: 1 False Count: 3
it should execute 1st getTrue() and then 1stGetFalse() and then 2nd getfalse() and should skip 2nd getTrue() and execute 3rd fetFalse()

-----
eXa.getTrue() && eXa.getTrue() || eXa.getFalse() && eXa.getTrue() || eXa.getFalse() comes as true and True Count: 2 False Count: 0

As per understanding it should be true with True Count: 3 False Count: 0
it should execute 1st 2 getTrue() and skip 1st getFalse() and then execute 3rd getTrue() and skip last getFalse().

-----
eXa.getTrue() || eXa.getFalse() && eXa.getFalse() || eXa.getTrue() && eXa.getFalse() comes as true and True Count: 1 False Count: 0

As per understanding it should be true with True Count: 2 False Count: 2
it should execute 1st getTrue() and skip 1st getFalse() and then execute 2nd getFalse() and then execute 2nd getTrue() and then 3rd getFalse()

Here is the methods definition:

private boolean getTrue() {
trueCount++;
boolean retrunValue = 4 > 3;
return retrunValue;
}

private boolean getFalse() {
falseCount++;
boolean retrunValue = 3 > 4;
return retrunValue;
}

Thanks for ur help
• ###### 1. Re: Regular expression evaluation with logical operator
>

adding parenthesis to make order of ops more obvious. adding "?" to show un-executed calls.
``````(eXa.getTrue() && eXa.getFalse()) || (eXa.getFalse() && eXa.getTrue()) || eXa.getFalse()  comes as false and True Count: 1 False Count: 3

(T && F) = F
(F && ?) = F
(F) = F

F || F || F = F

(eXa.getTrue() && eXa.getTrue()) || (eXa.getFalse() && eXa.getTrue()) || eXa.getFalse()  comes as true and True Count: 2 False Count: 0

(T && T) = T
(? && ?) = ?
(?) = ?

T || ? || ? = T

eXa.getTrue() || (eXa.getFalse() && eXa.getFalse()) || (eXa.getTrue() && eXa.getFalse())  comes as true and True Count: 1 False Count: 0

(T) = T
(? && ?) = ?
(? && ?) = ?

T || ? || ? = T``````
• ###### 2. Re: Regular expression evaluation with logical operator
By the way these are expressions, but not 'regular expressions'. Please don't misuse standard terminology.