Combining comparison operators with boolean operators


I’m totally new to this forum (and also pretty new to arduino), and I still need some help with some stuff.

Here’s a simple question (at least I think it is) that I have:

How do I correctly combine boolean operators with comparison operators?

Here’s the example that I’ve got right now (not going to copy the full code, it’s a bit long and all the integers are in dutch)

I’ve got 3 IR sensors which need to detect a black line, here’s my approach:

if (1006 < analogRead(IrL) < 1016 || 1005 < analogRead(IrM) < 1015 || 1010 < analogRead(IrR) < 1020) {
//command here

I don’t think this is correct, but I can’t find how to get it right. Can anyone help me on the way?

if (1006 < analogRead(IrL) < 1016
if (x > 1006 && x < 1016)

Of course, you’ll have to assign x first.

So is this is what it should look like?

if (analogRead(IrL) > 1006 && analogRead(IrL) < 1016 ||...)

You could do it like that, but the readings would be 100us apart - you're better off reading once and assigning the reading to a variable.

Yeah, but each IR sensor has a slightly different reading, so the intervals are different. I can't use the same variable for the 3 IR sensors.

So, use three different variables. Call them oh I don't know, leftReading, centreReading and rightReading