Something wrong but i don't know what

Hello :smiley:
i am a new one
So i try to learn the arduino language, and i work on a simple thing.
But this code have something wrong and i really don't know what. When i launch the arduino, just this code work

if ( a==1){
  digitalWrite(ledPin, HIGH );
  delay(100);
  digitalWrite(ledPin, LOW ); 
  delay(100);
   if (buttonState == HIGH) {
    // turn LED on:
    a=a+1;
   }
}

Like i click on the button and the write "if" work for a few seconds and after just this code work :confused:

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int a=0;
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  a=0;
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    a=a+1;
  } 
  if (a==0){
    digitalWrite(buttonState, LOW );
     if (buttonState == HIGH) {
    // turn LED on:
    a=a+1;
     }
  }
if ( a==1){
  digitalWrite(ledPin, HIGH );
  delay(100);
  digitalWrite(ledPin, LOW ); 
  delay(100);
   if (buttonState == HIGH) {
    // turn LED on:
    a=a+1;
   }
} 
  if (a==2){
    digitalWrite(ledPin, HIGH );
    delay(1000);
    digitalWrite(ledPin, LOW );
  delay(1000);
   if (buttonState == HIGH) {
    // turn LED on:
    a=a+1;
   }
  }
if (a==3) {
  digitalWrite(ledPin, HIGH);
  delay(1500);
  digitalWrite(ledPin, LOW);
  delay(100);
   if (buttonState == HIGH) {
    // turn LED on:
    a=a+1;
   }

if (a==4){
  a=0;
   if (buttonState == HIGH) {
    // turn LED on:
    a=a+1;
   }
}
}
}

Sorry for my English btw

you need to see the that the buttonPin is LOW before you increment "a" again.

if (HIGH == buttonState && LOW == lastButtonState) {
     // do something
}
lastButtonState = buttonState

you may also need to debounce the button

This line does not make sense:

    digitalWrite(buttonState, LOW );

'buttonState' is not a pin number!

What did you intend this line to do?