'else' without a previous 'if' in function 'void loop()'

When compiling, I get the error: "In function 'void loop()' " followed by " 'else' without a previous 'if' ". I've searched the web and arduino's old and new forums for similar posts, and the others have been solved by removing semicolons that end the initial if statement. I don't think this is my issue, and when I change 'else' to another 'if' statement, the code compiles just fine. The syntax error is probably right in front of my eyes, but does anyone have any thoughts?

Thanks. See the code excerpt below:

if(relayVal==1)
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
delay(5000); // delays 5s before moving to start position

else
{
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
delay(5000); // delays 5s before moving to start position

else is not part of the if as

delay(5000);    // delays 5s before moving to start position

is in between

kraken:
The syntax error is probably right in front of my eyes, but does anyone have any thoughts?

Yup. Sounds like the compiler told you exactly where to look.

kraken:

    }

}
    delay(5000);    // delays 5s before moving to start position
   
  else
  {

You broke the if-else with the delay().

Thanks guys. Until the next simple error...