Simple while loop not working as expected

Hey guys and girls,

I have a simple while loop made up with 2 leds. I ask user to tell how many times to blink the LED, when asking for input the sketch should wait. This works on the first argument for green LED, but when it comes to blue LED it jumps over it.

Can someone tell me what I am missing here (Please excuse my lack of uniformity when it comes to comments) :

//Global
  
  int ledGreen=10;   //Declare pin 10 for Green Led 
  int ledBlue=9;     //Declare pin 9 for Blue Led
  int ledRed=8;      //Declare pin 8 for Red Led
  int onTime=275;   
  int offTime=50;  
  int numberofBlinksGreen; 
  int numberofBlinksBlue;
  int numberofBlinksRed;
  String greenMessage="The Green LED is Blinking!";
  String blueMessage="The Blue LED is Blinking!";
  String redMessage="The Red LED is Blinking!";
  String blinkNumber="You are on Blink # ";
  String serialEnd="*****Loop Finished*****";




  
void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(9600);     // Starts Serial interface//disabled 

  String wm1="Welcome To ";
  String wm2="My Program Bitches!";
  String wm3;                       //Just declaring it
  wm3=wm1+wm2;                   //Concatenating wm1 and wm2 into wm3 

  Serial.println(wm3);
  Serial.println(" ");
  pinMode(ledGreen,OUTPUT);   //Enabling output to pin 10
  pinMode(ledBlue,OUTPUT);    //Enabling output to pin 9
  pinMode(ledRed,OUTPUT);      //Enabling output to pin 8 










}



void loop() {
  // put your main code here, to run repeatedly:




Serial.println("How man times do you want the Green LED to Blink?");
while (Serial.available()==0) { }
numberofBlinksGreen = Serial.parseInt();


Serial.println("How man times do you want the Blue LED to Blink?");
while (Serial.available()==0) { }
numberofBlinksBlue = Serial.parseInt();




  Serial.println(greenMessage);   //Start serial print new line
    
    for (int j=1; j<=numberofBlinksGreen; j=j+1 )  {                 
      Serial.print(blinkNumber);       //display blink #
      Serial.println(j);                   //new line on every blink #
      digitalWrite(ledGreen,HIGH);         //turn led on
      delay(onTime);                    //keep led on for specified time
      digitalWrite(ledGreen,LOW);          //turn led off
      delay(offTime);          //keep led off for specified time
}


  Serial.println(" ");                //adding serial print new line between sections of code will split up text between arguments

  Serial.println(blueMessage);   //start to display blue led notification

    for (int a=1; a<=numberofBlinksBlue; a=a+1) {       //for loop for blue led
      Serial.print(blinkNumber);      
      Serial.println(a);  
      digitalWrite(ledBlue,HIGH);
      delay(onTime);
      digitalWrite(ledBlue,LOW);
      delay(offTime);


}

  Serial.println(" ");
  
  Serial.println(redMessage);
    
    for (int r=1; r<=numberofBlinksRed ; r=r+1) {
      Serial.print(blinkNumber);
      Serial.println(r);
      digitalWrite(ledRed,HIGH);
      delay(onTime);
      digitalWrite(ledRed,LOW);
      delay(offTime);
}


  Serial.println(" ");
  Serial.println(serialEnd);
  Serial.println(" ");    //gives a space when starting the green led serial prints
  




}

Most likely your serial monitor is set to a line ending of crlf or lf. Set it to be nothing.

Well I'll be damned...

Can you explain to me the use of these?

The problem is that parseInt stops when it sees a character that isn't useful (digit or leading sign). So reading for green stops at the CR. When you parse for blue the LF is still unprocessed, so it kills the parse immediately, returning zero.