Hi,
Serial.available() returns the number of bytes (chars) available for reading.
If somehow more chars were entered then read then Serial.available() would never return 0 after that.
Instead of using while wrap the read(), print(a) and flush() in a IF statement which tests available().
Frederick