Flickering LED

while(y<=255 && button1State == LOW) //while LED is not fully lit and button 1 is pushed
{
analogWrite(ledPin, y); // turn the LED on gradually
delay(10);
button1State = digitalRead(button1Pin); //check state of button
y++; //step up y to increase brightness
Serial.println(y); //<<<<<<<< use Serial.print for debugging
}
}
else
{
while(y>=0 && button1State==HIGH) //while LED is not completely off and button 1 is not pushed
{
analogWrite(ledPin, y); // turn the LED on
delay(10);
button1State = digitalRead(button1Pin); //check state of button
y--; //step down y to decrease brightness
if (y<0) y=0; // Comment this line to see the problem on the serial monitor
Serial.println(y); //<<<<<<<< use Serial.print for debugging

Use Serial.println() to aid in troubleshooting code.