While statement confusion

I am trying to use a simple while statement but it doesn’t seem to be working.

//Test servo communication
int count = 0;
int Initiated = 0;
int panReady = 0;


void setup() {
  // initialize all serial ports:
  Serial.begin(9600);
  Serial1.begin(38400);
  //Serial2.begin(38400);
}

void panStatus(){
  while (Serial1.available() > 0){ //check servo com port
    byte panOut = Serial1.read();   
    if (panOut == '%'){ //check for servo ready
      Serial.print("ready"); //for trouble shooting com check
      count = 0;
      panReady = 1;
    }
    Serial.print(panOut);//for trouble shooting com check
  }
}
void loop() {
  panStatus();
  if(panReady == 1 && Initiated == 0){ //check if servo initialized
    Serial1.print("M3\r"); //set servo to position input
    panReady = 0;
    delay(50);
    //Serial1.print("E0\r"); //turn local echo off
    delay(50);
    Initiated = 1;
  }
  else if(panReady == 1 && Initiated != 0){ //check servo ready
    for(int i=1; i<6;i++){
      panStatus();
      Serial1.print("G1 "); //servo feed command
      Serial1.print(5000*i); //servo position to go to
      Serial1.print(" 2000\r"); //servo rotation speed
      panReady = 0;
      delay(100);
    }
  }
  else delay(100);
  //Serial.println(count++);//trouble shooting
}

it sould wait untill the servo sends back % before exicuting the next move but it doesn’t. I know it is most likely a simple error on my part, but it’s time to stop the hair loss and ask the experts.

Looks like I found the problem I have to do an extra while statement to check for the ready status. I had assumed it would stay in the while loop looking for % on port 1 during the panStatus loop, but it doesn’t seem to work that way. This is what has worked:

//Test servo communication
long positionPan = 5000;
int Initiated = 0;
int panReady = 0;
int i = 0;

void setup() {
  // initialize all serial ports:
  Serial.begin(9600);
  Serial1.begin(38400);
  //Serial2.begin(38400);
}

void panStatus(){
  while (Serial1.available() > 0){ //check servo com port
    byte panOut = Serial1.read();   
    if (panOut == '%'){ //check for servo ready
      Serial.print("ready"); //for trouble shooting com check
      panReady = 1;
    }
    Serial.print(panOut);//for trouble shooting com check
  }
}
void panMove(){  
  Serial1.print("G1 "); //servo feed command
  Serial1.print(positionPan); //servo position to go to
  Serial1.print(" 2000\r"); //servo rotation speed
  panReady = 0;
  delay(200);
}

void panInitial(){
  if(panReady == 1 && Initiated == 0){ //check if servo initialized
    Serial1.print("M3\r"); //set servo to position input
    panReady = 0;
    delay(50);
    //Serial1.print("E0\r"); //turn local echo off
    delay(50);
    Initiated = 1;
  }
}
void loop() {
  panStatus();
  panInitial();

  if(panReady == 1 && Initiated != 0){ //check servo ready
    for(int i=1; i<6;i++){
      while(panReady != 1){
        panStatus();
        delay(100);
      }

      panMove();
      positionPan += 10000;
    }
    positionPan = 0;
  }
  delay(100);

}