How can I exit my loop?

Hello. I had a question about how I could exit my loop after I printed something into the serial monitor. Whenever I print something it repeats over and and over again. I want it to stop and only print it once. The only way it does this is if I hit the reset button but I rather not do that. Here is the code.

String readString;

void setup()
{
Serial.begin(9600);
}
void loop()
{
while ( Serial.available()
)
{
delay( 3 );
char c = Serial.read();
readString += c;
}
if ( readString.length() >0 )
{
Serial.println( readString );
}
delay(1500);
}

Any help is greatly appreciated and thanks in advance.

 if ( readString.length() >0 )
   {
    Serial.println( readString );
    readString="";  //ADD THIS LINE  

  }

sst00: Hello. I had a question about how I could exit my loop after I printed something into the serial monitor. Whenever I print something it repeats over and and over again. I want it to stop and only print it once. The only way it does this is if I hit the reset button but I rather not do that. Here is the code. Any help is greatly appreciated and thanks in advance.

Really you have 1 problem and need 4 tips.

One tip is to use Autoformat in your IDE Tools menu. It's a big help for keeping track of indent levels.

Another tip is don't use C++ Strings in small memory environments like Arduinos. You can get away with it but you will not learn to use C string arrays but instead learn to depend on wasteful problematic Strings.

The third tip is to learn how to get past using delay(). The first link at the bottom of this post is an excellent tutorial about just that.

The last tip to use code tags, not quote tags to post your code inside.

String readString;

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  while ( Serial.available())   
  {
    delay( 3 );
    char c = Serial.read();
    readString += c;       
  }
  if ( readString.length() >0 )
  {
    Serial.println( readString );
  }
  delay(1500);
}

You could wrap everything inside of loop() inside of

if ( Serial.available() ) { }

and you should clear readString after your print it so any new input doesn't just append to the old.

If you want something to only run once, put it inside of setup(). I assume that you want to be able to echo message after message input from serial but maybe you don't.

Thanks KenF! That did the trick.