Expression condition evaluation

This is gonna be a real noob question. 

I was looking through an ex-colleague code. This is how it is written in a particular IF widget.


GetPerson(SelectedPerson).Person.LastName = "Alex" and IsCitizen = False

or

GetPerson(SelectedPerson).Person.LastName = "Cindy" and IsCitizen = True

or

GetPerson(SelectedPerson).Person.LastName = "Edward" and IsCitizen = False


I think he/she is trying to compare sets of data.


Does it make a difference in evaluation if i add parenthesis to the set?

(GetPerson(SelectedPerson).Person.LastName = "Alex" and IsCitizen = False)

or

(GetPerson(SelectedPerson).Person.LastName = "Cindy" and IsCitizen = True)

or

(GetPerson(SelectedPerson).Person.LastName = "Edward" and IsCitizen = False)


Please give me some insight if i got the things wrong instead. The reason i am asking this is because i think Outsystems being smarter than traditional environment might somehow evaluate things differently.

Hi,r

Of course you could debug this easy and find out yourself.

But the answer is that the parenthesis do make a diffenrence. Just as they don in other programming languages. 

So your code with parenthesis will execute different than the code of your ex coworker.

Regards,

Daniel

Dear Daniël

Thank you for verifying my doubts. I couldn't amend (and debug) the code hence i posted it here.

Solution

Hi Newbie,

As Daniel said, parentheses do matter, but I don't think the way you've added them would give different results then your colleague.  I think both '=' and 'and' already take precedence over 'or'


Dorine

Solution

I forgot i can test it on my own personal environment. I get to test out the scenario and dorine you are right that there is no differences.

Daniël is also correct that parentheses would made a difference too.

Hi, 

Just to sum up: https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Expressions/Operators#Precedence_of_Operators

Knowing the operator precedence is always easy than trying. The parenthesis content always have precedence over other operators. 

Cheers 

Given the two code examples, I would always prefer the one with parenthesis, it is just easier to read as it more explicitly describes the condition.

I do agree with you Daniel.