# SparkFun Forums

Where electronics enthusiasts find answers.

### need help with logics

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!

### need help with logics#200552

By alex.nev
#200552
hello evryone!
i`m a bit confused with the next thing. So i have x and y coords. I need do do an IF expression when both conditions are performed. Condition for X is when its in a range from 0,00 to 100,00 or over 230,00 and at the same time Y is in the range from 0,00 to 20,00 or over 180 then do {}

i`ve made it like

if (x<=100 || x>=230 && (y>=180 || y<20))

{
}

But you know its not working lika a charm...

Maybe there is a better solution for such logic like using an array? Im a newbie so don kick me too much))) Thanks guys!

### Re: need help with logics#200557

By jremington
#200557
Take a look at logical operator precedence and then decide if you are using the parentheses correctly.

Hint: since you are treating X and Y differently, for the same basic logical test, the answer is no.

### Re: need help with logics#200558

By DanV
#200558
You need more parenthesis:

if (x<=100 || x>=230 && (y>=180 || y<20))

if ((x<=100) || ((x>=230) && ((y>=180) || (y<20))))

You must be very precise about what comparison is being done where - leave no doubt.
Don't count on operator precedence, just brute force it.

### Re: need help with logics#200561

By jremington
#200561
You can, in fact, count on operator precedence. Guaranteed.

But most people don't bother to learn the rules that the compiler STRICTLY follows.

### Re: need help with logics#200562

By DanV
#200562
That's really what I was implying - don't count on what you may think you know about operator precedence.