Never exits loop to print out the final value, noob question but I'm exhuasted

So basically the following code never exits the for loop, and I need it to exit the for loop in order to print whatever the buffer finally contains once it’s looped through each char. However, as I previously stated, the loop (to my knowledge) just keeps on going and doesn’t end, hence why buffer is never printed OUTSIDE the loop (I am aware it print’s repeatedly inside the loop). I’m fairly certain and if statement with a break command would do the trick here however after staring at it for a while I still can’t figure out what it would be. Oh coding god’s, I humbly ask for your assistance!

char iValue;
const int bufflen = 10;
char buffer[bufflen];

void setup(){
  Serial.begin(9600);

  Serial.println(buffer);
int index = 0;
int i = 0;
for(i=0;i<bufflen;i++){
while (!Serial.available()) {

  ;

}
iValue = Serial.read();
buffer[index] = iValue;
//Serial.println(buffer);
//Serial.println(iValue);
Serial.println(buffer);
index++;
if (index > bufflen){
  break;
}
}

Serial.println(buffer);
}


void loop() {

}

The break statement is not necessary. What is necessary however is that you terminate the buffer string with a ‘\0’ character to signal the end of the string. You also have to ensure that you are sending enough characters to satisfy the exit condition Terminating cr/lf will count.

const int bufflen = 10;
char buffer[bufflen] = "";

void setup(){
  Serial.begin(115200);
  for(int i=0; i<bufflen-1; i++){
    while (!Serial.available());
    buffer[i] = Serial.read();
  }//for(i)
  buffer[bufflen-1]=0;
  Serial.println(buffer);
}


void loop() {

}

You’re also writing past the end of the buffer. If it’s buflen characters in length, the very last character is buffer[buflen-1] (the index is 0 based) Furthermore, you need to include an extra byte for the terminator described in answer 1.