error with "else" command

Hello there. im building a maze solving robot with two light sensors (one to detect bright light and one for dark light) and each time i compile it i get "Error: Syntax error around "else" " Its my first year of programming so im not knowledgeable of the syntax.

int main()
{ while(!stop_button())
      { while(analog(0)>150);
        while (analog(2)<150);
        motor(1,20);
        motor(2,20);
          sleep(0.5);
        
        while(analog(0)<=150);
        while(analog(2)<=150);
        motor(1,0);
        sleep(0.5);
        if(analog(2)>150);
           { motor(2,20);
            motor(0,0);
            sleep(1,0);
        }
        else 
           motor(0,20);
        motor(2,0);
            sleep(1,0);
        
    }
    return 0;
}

thank you very much

Try putting a { after else and } after sleep(1,0).

if(analog(2)>150);

I think this ";" is your culprit.
You only put ";" after a statement that does something like an assignment, or a function call. You don't put ";" after control statements like "if" condition or "while".

Did you mean to execute something like

if(analog(2)>150)
{ 
   motor(2,20);
   motor(0,0);
   sleep(1,0);
}

wherein the stuff in curly brackets gets executed when analog(2) is greater than 150? If so then that ";" after that "if" line in your code is not needed.

I also see that you have put some ";" after the while statements on line 3 & 4. Not sure if you really intended them. The compiler is not giving errors on those because they are resulting in "null" statements. But I'm not sure if you really meant them like that. Did you really mean to keep reading the analog(0) and do nothing until its reading came to <= 150?

thanks tttt! im not getting the error with my code anymore i will upload it to my micro controller to see if it works.