else if (right=left=200) //if right = left = 200
{
////
}
will the above code work ?
else if (right=left=200) //if right = left = 200
{
////
}
will the above code work ?
Yes, but it will not do what you obviously think it will do. Namely:
else if (right == 200 && left == 200) {...
Thanks. ![]()
This little program illustrates the problem:
void setup() {
// put your setup code here, to run once:
int right, left;
Serial.begin(9600);
right = 10;
left = 200;
if (right == 50) {
Serial.println("First expression");
} else {
if (right = left = 0) { // Note: set to zero
Serial.print("right = ");
Serial.print(right);
Serial.print(" left = ");
Serial.println(left);
}
}
}
void loop() {
}
If you assign any non-zero value to left and right, the second if expression evaluates to logic true. However, set them to zero and it evaluates to logic false and the if block is skipped. As aarg points out, this is probably not what you wanted.