Help using the serial monitor

I'm trying to print "Hello world" 10 times only when someone hits the enter key.
What I have so far:

byte bytefromKbd;
void setup(){
Serial.begin(9600);
Serial.println("Hit a key plus the [Enter] key to execute...:");
}

void loop(){
while(!Serial.available() == 13;
{
bytefromKbd = Serial.read();
for (bytefromKbd; bytefromKbd < 10; bytefromKbd++)
{Serial.println("Hello World");
}
}
}

Pretty sure my teacher wants me to use the ascii code for carriage return

Something is missing here:

  while(!Serial.available() == 13;

Can you see what is missing?

Your spacing should also give you a clue to how the compiler is going to interpret this. The not operator (!) sticks pretty tightly to the thing to its right. The equality operator (==) is almost the very last thing to be evaluated. So can NOT-available ever equal 13? It could only ever be true or false.

If you wanted not-equal, then you could use the inequality operator (!=). But then I would say that all of the time, Serial.available() will never get to 13.

13 looks special. It's what we call a "magic number". I already know that that's the ASCII value of carriage-return or line-feed. I don't bother remembering which is which. If I want to see if a byte is equal to one of those, then I'll use the C "escape codes" to write the special character instead of writing "13".

  if(bytefromKbd == '\n') {
    Serial.print("Hey, I just got a newline!");
  }
  if(bytefromKbd == '\r') {
    Serial.print("Hey, I just got a carriage-return!");
  }
 while (!Serial.available() == 13;

The code will not compile because you are missing a closing ) in the if statement.

That is not how to use the available() function. The available() function returns the number of bytes waiting in the serial input buffer. That if waits for 13 bytes to be available before executing. What you need to do is to see if there are 1 or more bytes available in the serial buffer, read those bytes into a string (null terminated character array) and then see if a enter (whatever characters you want for enter ['\n', '\r']) is in the string. The serial input basics tutorial will help with the reading of the incoming serial data.

@OP

1. Hitting on the 'Enter' key of the PC is equivalent to 'Clicking' on the 'Send' button of the Serial Monitor of UNO. So, there is no reason to understand that the Serial Monitor Interface will send 13 (the ASCII Code of Carriage Return) to the UNO when we hit the 'Enter' key of the PC.

2. To send 13 (the ASCII Code of carriage return) to the UNO, we need to active the 'Carriage return' option in the 'line ending formatting box' of the Serial Monitor and then either hit the "Enter' key of the PC or click on the 'Send' button of the Serial Monitor.

3. When we are dealing with the Serial Monitor Interface interaction in the loop() function using the Serial.read(); instruction, we are receiving one character and processing it; after that, we will receive the next character that is yet to arrive (MCU's speed is must faster than the Serial Interface Speed), process it and so on...!

4. You have wanted to print the Hello World message 10 times once the UNO receives the 'Enter' key's code which you have though to be 13. This is not correct as per opinion of Step-1. Please, change your statement to the following and only then we may help you. Will you do this?

"The UNO will print Hello World message 10 times once the UNO receives 'Carriage return' code (13) from the Serial Monitor."

byte bytefromKbd;
void setup(){
Serial.begin(9600);
Serial.println("Hit a key plus the [Enter] key to execute...:");
}

void loop(){
if(Serial.available())
{
bytefromKbd = Serial.read();
for (bytefromKbd; bytefromKbd < 10; bytefromKbd++)
{Serial.println("Hello World");
}
}
Serial.println();
Serial.println("Hit a key plus the [Enter] key to execute...:");
}

Is this closer? I have no experience with programming. The instructor said we wouldn't really need it but I'm struggling to understand this. The last part of code is meant to print that after "Hello world" is printed but instead it just prints it forever.

"if(Serial.available())"
{do something}

is checking to see if there's an input from the serial monitor I thought? Why isn't it doing anything when I hit a key and press enter?

Also I missinterpreted the "Hit a key PLUS the [Enter] key to execute...:" portion of the instructions. I'm slow. Lol.

That serial monitor tutorial is also kind of difficult to understand. I don't really get how the functions work. There's a function nested inside a function, nested inside a function? I thought serial.available just checks to see if there's an input in the buffer (Something entered by the user) then the code after executes if that's true. I'm confused.

Yes. But what is the value of bytefromKbd when it is received? All the characters you can type on the keyboard are greater than 10. So the for() loop looks at that and says that it is finished before it starts.

If you want to count from 1 to 10 or 0 to 9, then you need a new variable and you must give it the starting value every time.