My question remains. If the while statement sees that there is data, the delay statement can only result in an increase in the amount of data, not a decrease, since the only way to decrease the amount of data is to read it or flush it, neither of which the delay statement does. So, why is the if statement necessary?
Your belief that the delay is used to decrease the amount of data in the buffer is something you have created in your mind and only stated by you. I keep posting that the delay is to allow a short amount of time for all of a reasonibly short string to be put in the input buffer before the individual characters are extracted from the buffer and formed into a string. I find this to be very convienent when doing string testing in the arduino using the serial monitor. If the "if" statrment is not needed, then post the working code that doesn't use it and I will modify my test code accordingly.
The delay() masks the fact that there is no checking to see that a complete packet has arrived, because, coincidentally, if you wait long enough, the whole packet arrives, and you can pretend that all the data that did arrive constitutes a packet and nothing but a packet.
Wow, I think the light is starting to come on! That is all the delay does. It provides a short delay to help ensure the whole string is in the buffer before the buffer is capured into a string. With out the delay even fairly short test strings sent from the serial monitor will be captured in fragments, adding undesired issues into string testing activities.