AND OR handling

 

Hello folks,


might be a silly question for most of you, but I'm just running in a problem and would appreciate some clarification.


Sample:

if (Variable1 == Variable2 && Variable3 == Variable4 || VariableA == VariableB && VariableC == VariableD)
   {
   bool CriteraMet = true;
   }


As far I my understanding was/is does this code basically mean that "CriteriaMet" will be true if either the left of my or(||) or the right is true. Is this right or is this code handled different?


Thanks.

WorstCases

 

right, it's like:

if (Variable1 == Variable2 && Variable3 == Variable4)
   {
   bool CriteraMet = true;
   }

if (VariableA == VariableB && VariableC == VariableD)
   {
   bool CriteraMet = true;
   }
 

Thanks for your reply.


Does that mean that my sample code produce a different result compared to yours? If so: Can you please tell me why?

 

no, i said it's the same thing if you write like that

 

Oh - Sorry. My mistake.

Misread you post. Thought you said "Right is like..."

 
WorstCases:

Oh - Sorry. My mistake.

Misread you post. Thought you said "Right is like..."


that's y i put a comma usually i'm writing here without punctuation
 

Yeah. I see what you mean...

I have something else which I would like clarification. Added a >


Sample:

if (Variable1 == Variable2 && Variable3 == Variable4 || VariableA == VariableB && VariableC == VariableD > VariableX)
   {
   bool CriteraMet = true;
   }

As far I my understanding was/is does this code basically mean that "CriteriaMet" will be true if:

The left of my or(||) is true

OR

The right is true if A=B&C=D and both (ABCD) are > than X.

Is this right or is this code handled different?

 

wrong code

 
Is there any way I can approach what I was trying to do using only one "if"?
 

It depends on what the variable contains

(what u r trying to acomplish & what is wrong with 2 if's or more)

 

I want to execute an oder delete if certain criterias are met.


I mean: I could write it like this - and there is nothing wrong with it, I guess...?

if (Variable1 == Variable2 && Variable3 == Variable4)
   {
   bool CriteraMet = true;
   }

if (VariableA == VariableB && VariableC == VariableD > VariableX)
   {
   bool CriteraMet = true;
   }

Still the second if should mean the following:

The right is true if A=B&C=D and both (ABCD) are > than X.


I just thought it would look more clean if I only use one "if".

Reason: