computing
  • 0

Solved Break Statement Not Within Loop Or Switch

  • 0

I am using the Arduino Uno and am trying to control a stepper motor. I’m getting the error(“break statement not within loop or switch ) when I try and compile the following code: I want to break out of the loop if the first “if statement is true” Any suggestions??

void loop()
{

//Stepper motor will turn 90 degrees counterclockwise, VALVE WILL OPEN

if (ValveStatus==1) {
break; }
else if ((duration/74/2)<5) {

Serial.println (“OPEN VALVE”);
myStepper.step( -stepsPerRevolution);
delay(500);
ValveStatus++;
}

Share

1 Answer

  1. Use “return” rather than “break”. Better still, just rewrite the “if” statents to test if the required condition is met rather than if it is not met. I.e.

    if (Valve_Status != 1)
    if (…
    etc.

    message edited by ijack

    • 0