gearmotor test doesn't work

This simple test sketch gives me an else without if error, but it's right there before it. If I remove the else code it compiles. Is this a bug?

  const int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
  const int motor2Pin = 2;    // H-bridge leg 2 (pin 7, 2A)
  const int ledPin = 13;      // LED 
  const int button1Pin = 8;  //Forward button
  const int button2Pin = 9;  //Reverse button
  
    // variables will change:
  int buttonState1 = 0;         // variable for reading the pushbutton status
  int buttonState2 = 0;         // variable for reading the pushbutton status  
  
  
  void setup() {

    // set outputs:
    pinMode(motor1Pin, OUTPUT); 
    pinMode(motor2Pin, OUTPUT); 
    pinMode(ledPin, OUTPUT);
    pinMode(button1Pin, INPUT);
    pinMode(button2Pin, INPUT);
  }

  void loop() {
  // read the state of the pushbutton1 value:
  buttonState1 = digitalRead(button1Pin);
  // read the state of the pushbutton1 value:
  buttonState2 = digitalRead(button2Pin);

  if (buttonState1 == HIGH)    // check if a pushbutton is pressed.    
  {
    // turn LED on:    
    digitalWrite(ledPin, HIGH);      
    //turn motor on forward
    digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
    digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
  } 
  else if (buttonState2 == HIGH);     // check if a pushbutton is pressed.
  {
    // turn LED on:    
    digitalWrite(ledPin, HIGH);      
    //turn motor on backward
    digitalWrite(motor1Pin, HIGH);   // set leg 1 of the H-bridge low
    digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge high
  } 
  
  else {
    // turn LED off
    digitalWrite(ledPin, LOW);
    //turn motor off
    digitalWrite(motor1Pin, LOW);
    digitalWrite(motor2Pin, LOW);
  }
  
}

Extra semicolon:

else if (buttonState2 == HIGH); // check if a pushbutton is pressed

--
The Arduino Drum Machine: 14-track MIDI drum machine sequencer / groove-box

Try removing the ; on this line

else if (buttonState2 == HIGH);     // check if a pushbutton is pressed.
  {

Rob

Great! I was beginning to think it was a bug!

There ain't no pedant like a compiler!

Yea, never argue with your mother-in-law or a compiler, there is no upside, you can not win. :wink: