Clearing the serial buffer

I am working on a project where I communicate with an arduino Uno through the serial monitor. I send the arduino commands like "input" and "execute". If I send a command which the arduino does not recognize, I simply clear the serial buffer with the following code;

for(byte u=1; u=Serial.available();u++) // clear the remaining digits from the serial buffer 
             {
               byte discard = Serial.read();
             }

Where "discard" is sort of a dummy variable.

This works fine. However I believe that there should be the comparison operator "==" in the for loop condition. When I try to use the comparison operator as follows, my code doesn't work

 for(byte u=1; u==Serial.available();u++) // clear the remaining digits from the serial buffer 
             {
              byte discard = Serial.read();
             }

Can anyone explain why this may be?

Can anyone explain why this may be?

Because the middle condition of a for loop acts like a while.

An alternative method

while (Serial.available())
  {
    Serial.read();
  }

Which to me is more readable.

Thanks, that's much more concise!

In any case, the way that you are "clearing the buffer" is pointless. You are expecting that all of the data that makes up a packet is in the buffer before you start reading the buffer. Unless you are doing something quite bizarre, it is NOT. Dumping what is in the buffer after what you read will most likely NOT be the rest of the packet, so the next packet that you read will be wrong, too.

I do the following to make sure that all the data is in before anything else takes place. The 2ms delay is adequate for the baud rate I am using and the way I am sending the Uno the data.

  if(Serial.available()) //[1] if text is input, store the number of bytes and compare to # bytes 2ms later to see if all the data has been recieved.
  {
    byte ser = Serial.available();
    delay(2); 
    if(Serial.available()==ser) //[2] if no more data is coming in, do the following below
    {
//the rest of my code
     }