While loop behaving strangely

Hello All,
Recently I have been working with the Serial.available() function with some students. Attached is a screenshot of the code as well as serial output window. The code asks for the intake of a name, uses a while loop to wait for the serial buffer to have data in it. And then a second while loop to printout characters until the buffer is empty. In the example the name entered was "bob" and as can be seen in thee screen shot the second while loop doesn't seem to be doing its job. This is further verified by commenting out the while loop and just leaving print statement. Any help is greatly appreciated, as I am totally lost and have not experienced this issue before.

Arduino problem.jpg

I can't open the image.

(deleted)

The code asks for the intake of a name, uses a while loop to wait for the serial buffer to have data in it.

The first while loop waits for there to be some data in the buffer. "b" is some data.

The second while loop reads and prints all the data. "b" is all the data.

What is the problem?

I agree with Paul: it's doing exactly what you told it to do. As a variation:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Enter name:");  
}

void loop() {
  char name[15];
  int charsRead;
  
  while (true) {
    if (Serial.available() > 0) {
      charsRead = Serial.readBytesUntil('\n', name, sizeof(name) - 1);  // Save room for null
      name[charsRead] = '\0';
      break;
    }
  }
  Serial.println(name);

}

Don't waste people's time posting pictures of code. How could anyone look at that in a text editor. Post code directly in your Reply or as an attached .ino file.

You may find serial input basics useful.

...R