Logical boolean operators

Hi arduinos, I wrote a little piece of code that should increment values until they all reach their target value, but the function stops as soon as one value reaches its target. Shouldn't the WHILE loop stop only when all three values are equal to their respective targets because of the AND operators? Thanks

``````int R = 0;   //actual targets
int G = 0;
int B = 0;

int targetR = 10;  //target values
int targetG = 20;
int targetB = 30;

void setup() {
Serial.begin(9600);
}

void loop()  {

while (targetR != R && targetG != G && targetG != B){
smooth();
debugout();
}
}

void smooth(){
if (targetR > R){
R++;
}
if (targetG > G){
G++;
}
if (targetB > B){
B++;
}
}

void debugout(){
Serial.print("    R ");
Serial.print(R);
Serial.print("    G ");
Serial.print(G);
Serial.print("    B ");
Serial.print(B);
Serial.println();
}
``````

You are going to need OR operators for that. Alternatively, you might like to read this better, notice the "not" operator out front and the "finish condition" inside, so it is a "while not finished" loop.

``````while( ! (targetR == R && targetG == G && targetB == B))
``````

Oh look, you have a typo near the end, you have "targetG != B", that isn't going to be good either.

Oh :-[ yeah... got mixed up with the double negative stuff. I like the clarity of your arlternative! :) Thanks