Understanding the meaning of a code I found

Hey there,

So basically while searching on how to use bluetooth with arduino for school I found the following code:

//Arduino Turn LED On/Off using Serial Commands
//Created April 22, 2015
//Hammad Tariq, Incubator (Pakistan)




char junk;
String inputString="";

void setup()                   
{
 Serial.begin(9600);            
 pinMode(13, OUTPUT);
 pinMode(8, OUTPUT);
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); 
      inputString += inChar;        
    }
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { junk = Serial.read() ; }      
    if(inputString == "a"){         
      digitalWrite(13, HIGH);  
    }else if(inputString == "b"){  
      digitalWrite(13, LOW);
    }
     if(inputString == "c"){         
      digitalWrite(8, HIGH);  
    }else if(inputString == "d"){   
      digitalWrite(8, LOW);
    }
    inputString = "";
  }
}

I don't fully understand some of the things he has done, for example the part

if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); 
      inputString += inChar;

I was wondering if someone could explain this to me.

Thank you in advance!

That code is how to use the serial cons link - you’d be better off studying the examples on the IDE on serial coms if you want to do that .

This doesn’t use Bluetooth...

if (Serial.available()) //if at least one byte of serial data is available
{
  while (Serial.available())  //all the time there is still serial data available
  {
    char inChar = (char)Serial.read();  //read a character
    inputString += inChar;  //concatenate the new character with previously received characters
  }
}