if AND OR XOR NOT ...

dsnz

Well-known member
hello,

in an if when there are more than 2 conditions there is a drop-down to choose between AND , OR
I guess this means that it will consider the AND or OR of all conditions
this is understandable and fine

however as conditions I can choose

AND, OR, XOR, NOT clauses !!

which are displayed with () after them and it's confusing to me if they are logical clauses between the other if conditions (together with the above AND, OR ??) or something else ?
can anyone describe their purpose ?

see attached pic for example which I made as a random demo
what does it mean ?
 

Attachments

  • Screenshot_2021-05-11_143521~.jpg
    Screenshot_2021-05-11_143521~.jpg
    131.4 KB · Views: 24

Dm114

Well-known member
hello,

in an if when there are more than 2 conditions there is a drop-down to choose between AND , OR
I guess this means that it will consider the AND or OR of all conditions
this is understandable and fine

however as conditions I can choose

AND, OR, XOR, NOT clauses !!

which are displayed with () after them and it's confusing to me if they are logical clauses between the other if conditions (together with the above AND, OR ??) or something else ?
can anyone describe their purpose ?

see attached pic for example which I made as a random demo
what does it mean ?
These logical operators are useful when you have to combine some of them in an 'if' statement or a constraint.

In an 'if' statement, the only operator you can use is either 'and' or 'or' (on the top of the condition window) and it applies to all the conditions of the statement. If you must mix them like in 'Condition A' AND (Condition B OR Condition C)' (i.e. [A and B] or [A and C]) you'll use:
AND (general statement operator)
• Condition A
• OR (MD operator)
|> Condition B (1st constraint of the OR operator)
|> Condition C (2nd constraint of the OR operator)

According to the constraints, in a trigger for instance, they are all linked by an implicit 'and' i.e. all constraints have to be 'true' for the trigger to fire. You may need either the 'negation' (NOT) of a constraint or to link some of them by an 'OR'.

These are some simple and common examples. Hope I was clear enough.
 

Pseudocyclic

Well-known member
Normally, condition must return true for process to proceed. When NOT is used, condition must return false for process to proceed.

When XOR is used, true is returned when an odd number of its conditions return true.
 

Dm114

Well-known member
Normally, condition must return true for process to proceed. When NOT is used, condition must return false for process to proceed.

When XOR is used, true is returned when an odd number of its conditions return true.
Is 'odd' the exact word?

'XOR' (eXclusive OR) means 'only ONE of the conditions' has to be true instead of 'OR' that means 'any or all of them'.
 

dsnz

Well-known member
These logical operators are useful when you have to combine some of them in an 'if' statement or a constraint.

In an 'if' statement, the only operator you can use is either 'and' or 'or' (on the top of the condition window) and it applies to all the conditions of the statement. If you must mix them like in 'Condition A' AND (Condition B OR Condition C)' (i.e. [A and B] or [A and C]) you'll use:
AND (general statement operator)
• Condition A
• OR (MD operator)
|> Condition B (1st constraint of the OR operator)
|> Condition C (2nd constraint of the OR operator)

According to the constraints, in a trigger for instance, they are all linked by an implicit 'and' i.e. all constraints have to be 'true' for the trigger to fire. You may need either the 'negation' (NOT) of a constraint or to link some of them by an 'OR'.

These are some simple and common examples. Hope I was clear enough.
since there are no parentheses and the clauses (conditions and condition operators - as you called them ) are just listed vertically , then how are they grouped ??

can you attach the code for your example ?
(and perhaps tell me also how you read/decode my random example that I had attached)
 

Pseudocyclic

Well-known member
Is 'odd' the exact word?

'XOR' (eXclusive OR) means 'only ONE of the conditions' has to be true instead of 'OR' that means 'any or all of them'.
You are right, doesn't matter how many conditions are false, one condition only must be true.
 

Dm114

Well-known member
since there are no parentheses and the clauses (conditions and condition operators - as you called them ) are just listed vertically , then how are they grouped ??

can you attach the code for your example ?
(and perhaps tell me also how you read/decode my random example that I had attached)
In your example, only 'in call' and 'wifi enabled' conditions (linked with an 'or' operator) make sense. The 4 other operators are useless because you haven't associated any condition (constraint) to them.

According to parentheses, I've put them in the explanation → A and (B or C).

In my example attached, to be true, the conditions are 'STR=OK' AND (INT<0 OR INT>100) i.e. if STR equals OK, INT must be either <0 OR >100.
 

Attachments

  • Screenshot_20210511-184849_MacroDroid.jpg
    Screenshot_20210511-184849_MacroDroid.jpg
    359.3 KB · Views: 34

dsnz

Well-known member
ah !
thanks to your example I can see now that the "operators" act on child constraints (a constraint is equivalent to a test or a boolean value)

this is not immediately obvious to a user,
but as I see now (on further check after your post) it's explained in help , so it's my mistake that I didn't try to read it ...

all is understood now

thank you
 

MacroDroidDev

Administrator
Staff member
I have seen other new users get confused how to use these, so I'd welcome any suggestions how to help new users understand how they work.

My initial thought would be to throw up an info dialog on first usage explaining the operator will apply to any child elements, with maybe an example screenshot as above. Does that sound good?
 
Top