This discussion is archived
2 Replies Latest reply: Oct 30, 2012 1:26 PM by EJP RSS

Regular expression evaluation with logical operator

783105 Newbie
Currently Being Moderated
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()

Please help me to understand above expressions.


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
    jtahlborn Expert
    Currently Being Moderated
    >

    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
    EJP Guru
    Currently Being Moderated
    By the way these are expressions, but not 'regular expressions'. Please don't misuse standard terminology.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points