serial input to arduino

Not true. Look it up and find out why!

How can the if test get executed if the while test did not determine that there was serial data available?

If the while test found that there was serial data available, how can the delay make it go away?

Where would you expect me to look up these answers?