??? Behavior of Serial.read() ???

Hi folks!

I have a question about behavior of Serial.read() function.

void readData(){
  if (Serial.available() > 0) {
    incomingBufferLenght = 0;
    for(int i = 0; i < Serial.available(); i++){
      ....and some other processing stuff...

Im working with MIDI and here reciveing SysEx messages. In this case I can have continuously incoming messages.
What I am interested in is a situation, when I have a looong incoming connection (lots of bytes) and those bytes will keep comming while I will be reading the que with the cycle and Serial.read(). What will happen to Int I am getting from Serial.available()? Will it be incrementing with incoming bytes to serial interface?

Im asking, if i can just keep it like this and the cycle will finish only when there are no data to read on serial interface, even if they came in the meantime of processing previous bytes, and when finish, I can just Serial.flush() it, without being worried that I accidentaly flushed also data that came after first run of the cycle.

I hope its clear :),

Serial.available() returns the number of bytes that are available at the moment it is called. That can be in the middle of a transmission from another device.

For example, if I type "hello world" in the Arduino serial monitor and click "send", Serial.available() probably won't return 12 right away - it might return 2, then 6, then 9, or whatever, depending on how quickly you're calling it.