-1

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.

  • 2
    `it will give me an error while debugging`: what error when you do what? BTW trhere are 3 conditions in your code snippet and your code cannot compile, let alone be debugged...Maybe you want to [edit] and clarify. – Jabberwocky Mar 24 '23 at 12:26
  • 2
    `control = 10000 || control = 80000` -> `control == 10000 || control == 80000` – Jabberwocky Mar 24 '23 at 12:26
  • 1
    Please elaborate on what the "error" is. Is the branch taken although you do not want it to do so? Or vice-versa? Or is there some other error? Also, what is `P2IN`? If possible, please provide a [mre] of the problem. – Andreas Wenzel Mar 24 '23 at 12:27
  • 1
    You are also missing one closing bracket in provided code. – kriplerm Mar 24 '23 at 12:28
  • I guess (emphasis on "guess") you want this: `if ( (control == 10000 || control == 80000) && ((P2IN & 0x02) == 0) )`. [Edit] and write the conditions in plain english. E.g. "if `control` is either 10000 or 80000, and if `P2IN & 0x02` is 0, then do something". – Jabberwocky Mar 24 '23 at 12:28
  • 1
    This code doesn't compile. Please show the *actual* code you're using. – dbush Mar 24 '23 at 12:32

1 Answers1

4

(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))

0___________
  • 60,014
  • 4
  • 34
  • 74