cancel
Showing results for 
Search instead for 
Did you mean: 

Blue Prism unexpected OR, AND precedence

MichalPlich2
Level 4
Please take a look at example below. Is there any reason why BP interprets this operation as False?
Is OR operator higher Precedence than AND in BP?
17024.png


------------------------------
Michal Plich
PD
Nordea
Europe/Oslo
------------------------------
5 REPLIES 5

ewilson
Staff
Staff
Hi @MichalPlich2,

According to Microsoft, logical operators guarantee evaluation of their operands from left to right. However, they evaluate the smallest number of operands needed to determine the result of the expression. This is what's referred to as "short-circuit" evaluation. As a result, some operands of an expression may not be evaluated. Further, the logical AND operator has higher precedence than the logical OR operator.

Now, if you wrapped this equation as (1=2 AND 2=2) OR (2=2) then you'd see a True result.

Cheers,



------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------

I am splitting hairs with this, but my nerd light turned on my head so I couldn't help myself. The result of what you described is absolutely right, and I'd say it's important to always use parentheses to ensure the order of operations is exactly as intended. I'm purely responding because it's interesting and this has caused me to learn something. 😃

I don't think Blue Prism's expression syntax uses short circuit, since there's no support for AndAlso. Of course, I'm making the assumption that Blue Prism's Expression Syntax is directly based on VB.NET rather than it being abstracted/overridden with a different implementation. In Michal's example, I believe it's the operator precedence (which you mentioned) that causes his expression to evaluate to False.

In Blue Prism expressions, it would seem that this:
1=2 AND 1=1 OR 2=2
is equal to this:
(1=2) AND (1=1 OR 2=2)

Because AND has higher precedence (which of course I know you pointed out, so nothing new here), we can flip it around, and these expressions also evaluate to False:
1=1 OR 2=2 AND 1=2
(1=1 OR 2=2) AND (1=2)

And I think this is a good example that results in True showing that AND takes precedence:
1=1 OR 1=2 AND 2=2

If OR and AND were equal in precedence then this expression would result in True but instead it results in False:
1=1 OR 1=2 AND 2=3
But the only way to get True on that is to force the order of operations:
(1=1) OR (1=2 AND 2=3)

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company

Good point about the lack of AndAlso and OrElse operators in Blue Prism @Dave Morris. I'd say you are correct about the lack of short-circuit evaluation w/o them. That's what I get for overlaying my C# bias. 🙂

Cheers,


------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------

As a side note, there is a suggestion in the idea portal to add short-circuited logical operators, if anyone wants to upvote it. I think it would be very useful to have AndAlso and OrElse in Blue Prism expressions.

------------------------------
Nicholas Zejdlik
RPA Developer
------------------------------

I voted for it just now. That kind of functionality would go well with If statement support in Expressions as well.

------------------------------
Dave Morris
Cano Ai
Atlanta, GA
------------------------------

Dave Morris, 3Ci at Southern Company