Restart loop() inside if-statement

Dear Community,

I try to restart the loop()-function within an if-statement but it doesn’t work. Here is my example code:

#include <PID_v1.h>
double kp = 0.1;
double ki = 0.1;
double kd = 0;
double setpoint = 1;
double input = 0.2;
double output = 0;

PID myPID(&input, &output, &setpoint, kp, ki, kd, DIRECT);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  myPID.SetMode(AUTOMATIC);
}


void loop() {
  // put your main code here, to run repeatedly:
if(myPID.Compute())
{
  Serial.print(output); Serial.print("  ");
  loop();
  Serial.println("Why print this?");
}
delay(100);

}

When I put the “loop()” command outside the if-statement it works fine. How can I restart the loop when myPID.Compute() is true?

Thanks in advance.

Just do a "return".

Going recursive is dangerous

Thank you for your fast answer :wink: That works fine!

Dave