Solved break statement not within loop or switch

May 18, 2014 at 22:27:56
Specs: Windows 7
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++;
}

message edited by GGP32


See More: break statement not within loop or switch

Report •

#1
May 18, 2014 at 23:04:54
✔ Best Answer
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


Report •
Related Solutions


Ask Question