if(Serial.available()>0) VS while(Serial.available()>0) What's the low level difference between if(Serial.available() &gt; 0) and while(Serial.available() &gt; 0)? On what conditions would you choose one over the other?
I was testing my codes on 4 daisy chained 74HC595 shift registers controlling multiple LEDs. The code takes in a number from the serial monitor and displays it out in binary via the LEDs. Here is the code below that worked:
#define latchPin 8  //ST_CP pin of 74HC595
#define clockPin 9  //SH_CP pin of 74HC595
#define dataPin 7   //DS pin of 74HC595

//number of 74HC595 in daisy chain
#define numOfDaisyChainReg 4

byte registerVal[numOfDaisyChainReg];

void setup() {
    Serial.begin(115200);
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
}

void loop() {

  while (Serial.available() &gt; 0) {
    
    uint32_t num = Serial.parseInt();
    Serial.print(num, DEC);
    Serial.print(&quot; : &quot;);
    Serial.println(num, BIN);

    //breaks the recieved int into 4 unsigned bytes
    //and assigns the byte value into the &quot;registerVal&quot; array
    for (uint8_t a = 0; a &lt; numOfDaisyChainReg; a++) {
      registerVal[a] = (num &gt;&gt; (numOfDaisyChainReg - (a + 1)) * 8) &amp; 0xFF;
      Serial.print(&quot;registerVal[&quot;); Serial.print(a); Serial.print(&quot;] = &quot;);
      Serial.println(registerVal[a], BIN);
    }

    //writes the 4 bytes into the shift register
    digitalWrite(latchPin, LOW);
    for (uint8_t x = 0; x &lt; numOfDaisyChainReg; x++) {
      shiftOut(dataPin, clockPin, MSBFIRST, registerVal[x]);
    }
    digitalWrite(latchPin, HIGH);
    
  }
    
}

Originally, I had if(Serial.available() &gt; 0) and that didn't work as no LEDs lit up despite everything else in the code working as it was expected. Switching to while(Serial.available() &gt; 0) solved that problem. Anyone have any idea why that's the case?
I figured out why while(Serial.available()&gt;0) and if(Serial.available() &gt; 0) would or would NOT work in terms of my shift register code. It has to do with the serial monitor line feed and carriage return setting! If it isn't set to no line ending, it will either not register the input number or reset it back to zero right after the input is read. Learned to always check the line return option in the serial monitor! With this solved, the original question is nothing more than a general if vs while statement; which I already know the answer.
Thanks to everyone who contributed to this question! It did help me understand a lot more about Serial.available() in general. @jsotola gave a really good article. Combined with this YouTube video, it makes a lot more sense now.