'else' without a previous 'if'

Hello everyone,

I'm a newby in Arrduino so i must ask you to solve this problem.

I've done a program and this error message pop when i verify my code:
'else' without a previous 'if'
I don't understand because there is 2 If and 2 Else ...

You can see my code beside and please help me to fix it!

#include <DRV8835MotorShield.h>
int buttonPin = 13;
DRV8835MotorShield motors;

void setup()
{
  
if(digitalRead(buttonPin)==HIGH); // si test 1
  {
  for (int speed = 0; speed <= 255; speed++)
  motors.setM1Speed(speed);
  delay(4815);

  motors.setM1Speed(255);
  delay(9630);

  for (int speed = 400; speed >= 0; speed--)
  motors.setM1Speed(85);
  delay(4815);

  motors.setM1Speed(0);
  delay(10000);

  for (int speed = 0; speed <= 255; speed++)
  motors.setM1Speed(speed);
  delay(4815);

    if(digitalRead(buttonPin)==HIGH) // si test 2
    motors.setM1Speed(255);
    else // sinon test 2
    motors.setM1Speed(0);
  }
else // sinon test 1
motors.setM1Speed(0);

}

void loop() {}

(Sorry for my english i'm french^^ And i hope i've done a subject in the rules of the forum)

if(digitalRead(buttonPin)==HIGH); <———<<<< get rid of the ;

An if statement conditionally executes the statement or block immediately following the if.

A ; is an empty statement.

So this code:

if (test==1); 
{ 
   doSomething();
   doSomethingElse();
}

will check if test is equal to one. If it is, it will execute the following statement, which is the ; on the same line, which does nothing. At that point the if is done, so the stuff in the following block {} will be executed whether or not the condition of the if statement was true.

The correct form is:

if (test==1)
{ 
   doSomething();
   doSomethingElse();
}

which will execute the block between the {}'s only if test is equal to 1.

So yeah, that's why the line with an if() on it doesn't want a ; at the end.