When you enter a character, your program determines that there is serial data to read, and it reads that character.
I determines that the character is the letter a, so this code is executed:
if(Serial.available() > 0)
This loop waits until another character arrives at the serial port. As soon as it arrives, and it doesn't matter what it is, the LED on pin 13 is turned on, one second is wasted, the LED on pin 13 is turned off, another second is wasted, then a jump out of the while loop occurs.
Then, you actually read that character.
If the character that was entered initially was NOT the letter a, you read the next character (there may not be one) and see if the next character is the letter b.
Take some time to write down exactly what you want to send to the serial port, and exactly what you want to have happen when that data arrives at the serial port. Then, we can help you make that happen.
Randomly rewriting the code without a clear set of requirements is an exercise in frustration for all concerned.