RedDirtCyclist:
I would prefer to do so myself, and thank you for that. That gives me something to go on and I will see what I can come up with.
The task will be easier to do if we know what the following code is doing by breaking it down into multi-line codes:
while ( Serial.available() == 0 )
{
}
When a characters is sent to the UNO from the InputBox of the Serial Monitor (Fig-1), the character is captured by UNO and is saved in a FIFO (first-in first-out) type buffer. So, a user program first checks if the buffer has accumulated any (at least one) character and then the user brings out the character from the buffer into a variable. That means that the user program keeps checking the content of the buffer until a non-zero value is found. Therefore, the following codes are in logical order:
void loop()
{
byte n = Serial.available(); //read the content of buffer
if(n !=0 ) //buffer contains at least one character
{
char x = Serial.read(); //bring out the character from buffer and save in x
}
} //buffer holds no character/data byte; check again
If you are asked to reduce the 3-line codes of the of the above sketch, you would certainly come up with the following answer:
void loop()
{
while(Serial.available() == 0) //keep reading the buffer until it holds a character/data byte
{
}
char x = Serial.read();
}
Serial Monitor

Figure-1: Detailed structure of Serial Monitor
(1) If 'Newline' option is selected in the line ending tab, the Serial Monitor sends 0x0A (ASCII code for Newline (\n)) at the end of sending the character (s) of the InputBox.
(2) If 'Carriage return' option is selected in the line ending tab, the Serial Monitor sends 0x0D (ASCII code for Carriage return (\r)) at the end of sending the character (s) of the InputBox.
(3) If 'Both NL & CR' option is selected in the line ending tab, the Serial Monitor sends 0x0D and then 0x0A (ASCII codes for Carriage return and Newline (\r\n)) at the end of sending the character (s) of the InputBox.
(4) If 'No line ending' option is selected in the line ending tab, the Serial Monitor sends no code at the end of sending the character (s) of the InputBox.
