serial event

Hi

I am working on a project that includes an Arduino Uno reading some temperature sensors and passing the data to my pc thru serial communication.
If I understood correctly, the "serialEvent" function interrupts the program and is activated when there is some data to read in the receive serial bus.
so if what I said is correct... my question is why in all the examples I saw that use the "serialEvent" function, the first code line inside the function is the next while loop:

while(Serial.available()){
}

isn't it doing the same thing? because Serial.available() returns the number of bytes there are to read from the receive serial bus?

thanks

Read this https://forum.arduino.cc/index.php?topic=396450

If I understood correctly, the "serialEvent" function interrupts the program

That is not what it does. Rather, if serial data is available the serialEvent() function is called at the end of loop() and as such can simply be replaced by

if (Serial.available())

or

while (Serial.available())

anywhere you like in your sketch

The difference between the two is that if will only check for serial data once each time it is executed whilst the code in the while code block will execute as many times as necessary to read all of the available data