while(Serial.available()==0) {} loop falls through

Can you share exactly what you type, how you enter the data, from which serial input and what the console exactly prints?

What I Suspect is as follow

while(Serial.available()==0) {} // pause to copy numbers
// OK to here -- falls through the next *while* loops

I suspect you type something here to go thru and As you don't read the buffer, the next time you call available() there is still something in there that you did not empty and thus it goes thru.

Would be interesting also depending on your input to know how you set up timeout