how to stop a loop arduino

arduino, c, loops

Solution

Arduino specifically provides absolutely no way to exit their `loop` function, as exhibited by the code that actually runs it:

setup();

for (;;) {
    loop();
    if (serialEventRun) serialEventRun();
}

Besides, on a microcontroller there isn't anything to exit to in the first place.

The closest you can do is to just halt the processor. That will stop processing until it's reset.

Problem

I have this loop, how would I end the loop? ``` void loop() { // read the pushbutton input pin: a ++; Serial.println(a); analogWrite(speakerOut, NULL); if(a > 50 && a < 300){ analogWrite(speakerOut, 200); } if(a <= 49){ analogWrite(speakerOut, NULL); } if(a >= 300 && a <= 2499){ analogWrite(speakerOut, NULL); } ```

Original source