breaking a single looping instance of void loop

Hi guys,
I have a very noobie question, I’m sure its quite simple yet I’m not sure how to google it so I thought to give it a try here with a short explanation.
I’m using a function to fetch a JSON with http request, a code from an online guide:

String httpGETRequest(const char* serverName) {
// ... fetch the data ....
 if (httpResponseCode>0) {
    Serial.print("HTTP Response code: "); Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: "); Serial.println(httpResponseCode);
  }
}

I’m not sure how come this function is delcared as “String”, but hi… it works.
Anyway, I call this function from “void loop{}” of the main code of my program.
What I am trying to do, is that in case I am having an error code < 0, which is handled in the “else” statement of that function, I want to break the instance of the void loop on the spot and start a new void loop immediately, without running the rest of the code of “void loop” that written after returning back from the function.

What can you suggest me to do?

Hope I was clear.

Thanks,
Ran

Use

break;

Don't say "instance" when you mean "execution". It has another meaning in the context of C++ classes.

aarg:
Use

break;

Wow that was fast response!
So break; will also break the void loop{} instance, not just go out of the IF and the function?
BTW, what it means that this functions is a declaration of String, that means it return a String?

Thanks

Edit: Sorry.. execution :slight_smile:

So I tried this code in the String function of fetching the JSON:

  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: "); Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: "); Serial.println(httpResponseCode);
    Serial.println("Breaking the execution for new one...");
    lcd.clear();
    lcd.print("Oops! Try again");
    break;
  }

And I get this error:

exit status 1
break statement not within loop or switch

It seems I can't place the break; in the IF, but I would like to stop the execution right there and not even returning to the void loop and then check if I got the else and then break it. Do you have an idea how to maybe?
Is there a way to just call the void loop or void setup and therefore breaking the current execution and making a new one? Perhaps to reset the device even.. (although that will be my least favorite option)

Thanks