Alexa Martínez
Alexa Martínez

Reputation: 11

Logic operator AND (&&) code composer is not working

I'm trying to write a code in which two conditionals must be meet in order to follow the cycle, but it's not working.

If ((control = 10000 || control = 80000) && if((P2IN&0x02)==0)

If I do this, it will give me an error while debugging, but I don't where the mistake is.

Upvotes: -1

Views: 164

Answers (1)

0___________
0___________

Reputation: 67855

(control = 10000 || control = 80000) it will always evaluate to the true as

you assign the control with 10000 and in C language any non zero value is considered as true. The second part of the || will not be evaluated because of the shorthand evaluation

You should read the warning as the compiler definitely has warned you about it

If I do this, it will give me an error while debugging, but I don't where the mistake is.

You did not get to the debugging as this code would not compile. The second part is invalid as you do not need the second if (invalid syntax)

It should be if ((control == 10000 || control == 80000) && !(P2IN & 0x02))

Upvotes: 4

Related Questions