Don't know how to use return statements

String R;
int x=0;
void setup() {
  Serial.begin(9600);
  String R=Serial.readString();
}

void loop() {
  Serial.println("Hello");
  x++;
  if(x==1)
  {
     Serial.println("Would you like to say something?");
     while(Serial.available() == 0){}
     if(R== "yes")
     {
       Serial.println("No thank you, more code will be needed");
      return;
     }
     if(R != "yes")
     {
      Serial.println("Thank you");
      return;
     }
  }

}

Hello and nice day! What I have above is a program i made to test out the return statement.
I am trying to make it so the code will ask again "Would you like to say something" after you make an input into the Serial monitor. What happens though, is that my code run as normal up until I input something into the serial monitor.
When i input, it says the corresponding response but then it goes back to the "hello" statement so meaning it went too far back from what i intended it to. How do I make it so it only returns the if(x==1) part of the code and not the "Hello"

“return” exit the current function, in this case loop(). Because loop() is itself in a sort of loop ( it is called repeatedly) , it simply starts again from the top.

Your code (since it looks like it should be executed once only) does not really belong in the loop() function. It should, in this case, all be in setup().