Use of && and ||

Can you use the && and the || operators together like this?

example:

if ((SensorState == HIGH) && (state = MODE1) || (state = MODE2) || (state = MODE3))
{
}

Can you use the && and the || operators together like this?

Yes, you have our permission to do that.

Of course, it won't do what you expect, mixing assignment and equality operators like that...

Proietti:
Can you use the && and the || operators together like this?

You seem to be using = where you should be using ==

Yes, you can use a combination of and and or (I prefer to use the words as it makes code easier to read IMHO)

However getting a complex test like that correct (so it does what you actually want) can be a challenge and if it is wrong it can be difficult to debug.

I suggest you use a cascade of tests

 if ((SensorState == HIGH) {
     if (state == MODE1) or (state == MODE2) or (state == MODE3) {


    }
}

Another thing to keep in mind is that you have no means to know which of the OR statements caused the test to fail. There is one way for the second line to be TRUE and 7 ways for it to be FALSE

…R

Or use more parenthesis.

Thanks

Robin2:

 if ((SensorState == HIGH) {

if (state == MODE1) or (state == MODE2) or (state == MODE3) {
    }
}

Doesn't the first && take precedence over the following || statements?

I read OP's example as:

  if (((SensorState == HIGH) && (state == MODE1)) || (state == MODE2) || (state == MODE3)))

So: if SensorState HIGH and state is MODE1, or state is MODE2, or state = MODE3.