Does Serial.print affects serial recieve buffer?

if available() gets the number of bytes arrived and stored in the serial recieve buffer, how come the result of the code bellow is just printing.
(when i lunch the program, the result on the serial monitor is: printprintprintprintprint....)

char inByte = 0;

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

void loop ()
{
Serial.print("print");
while (Serial.available()>0){
inByte = Serial.read();
Serial.print(inByte);
}
}

What should i do program to stop after serial.print("print")
(print and then wait till you recieve at least 1 byte)

thank you very much

If you are sending nothing to the serial port, the while loop has no affect, so your program is equivalent to:

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

void loop ()
{
   Serial.print("print");
}

Which should make it pretty obvious why it keeps printing "print" over and over.

PaulS:
If you are sending nothing to the serial port, the while loop has no affect, so your program is equivalent to:

void setup (){

Serial.begin(9600);
}

void loop ()
{
   Serial.print("print");
}



Which should make it pretty obvious why it keeps printing "print" over and over.

Do you maybe know, what should i do program to stop after print() and wait for some incoming byte from serial monitor and then go on?

difenbahij:
Do you maybe know, what should i do program to stop after print() and wait for some incoming byte from serial monitor and then go on?

change your while statement.

Edit: Incorrect code removed. Thanks Paul

difenbahij:
if available() gets the number of bytes arrived and stored in the serial recieve buffer, how come the result of the code bellow is just printing.
(when i lunch the program, the result on the serial monitor is: printprintprintprintprint....)

char inByte = 0;

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

void loop ()
{
Serial.print("print");
while (Serial.available()>0){
inByte = Serial.read();
Serial.print(inByte);
}
}

What should i do program to stop after serial.print("print")
(print and then wait till you recieve at least 1 byte)

thank you very much

char inByte;

if (Serial.available())
{
inByte = Serial.read();
Serial.print(inByte);
}

///if there's nothing there, it will loop and start again, it does not 'wait' it simply gives yes/no answer and then you get the data.

tnx, but

void loop(){
Serial.print("text");
if (Serial.available()){
inByte = Serial.read();
Serial.print(inByte);
}
}

also prints "text" over and over again

char inByte = 0;

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

void loop ()
{
   Serial.print("print ");
   while (Serial.available()==0)
      ;  // Do nothing
     inByte = Serial.read();
     Serial.println(inByte);
}
   while (Serial.available()<=0){  // waits until a byte is sent
     inByte = Serial.read();
     Serial.print(inByte);
   }

Come on, James. You know better than that. While there is nothing to read, read it?

PaulS:
Come on, James. You know better than that. While there is nothing to read, read it?

Well gee, when you put it that way, the whole loop looks kinda silly, doesn't it? :wink: