Simpler way to write this simple program?

if (digitalRead(button) == HIGH)
{
analogWrite(led, 51);
delay(500);
analogWrite(led, 102);
delay(500);
analogWrite(led, 153);
delay(500);
analogWrite(led, 204);
delay(500);
analogWrite(led, 255);
delay(500);
analogWrite(led, 0);
}

Im using PWM with a LED and a button. how can I write this without being repetitive and how would i make it if I want to increase the value by 10 maybe, because I know to add one you can do something like x++. I am a noob lol help.

Thanks

maybe this?:

if (digitalRead(button) == HIGH)
  {
   ledLevel = 51;
   for (x=0; x<6; x=x+1){
   analogWrite(led, 51);
   delay(500);
   ledLevel = ledLevel +51;
   }
analogWrite(led, 0);

or
this

byte ledLevel[] = {52,102, 153, 205, 255, 0};
if (digitalRead(button) == HIGH)
  {
   for (x=0; x<5; x=x+1){
   analogWrite(led, ledLeve[x]);
   delay(500);
   }
analogWrite(led, ledLeve[5]);

without the typos, of course ...

the fade example included in the IDE is a good starting point, too.

int led = 9;           // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
void setup()  
{ 
  pinMode(led, OUTPUT);
} 
void loop()  
{ 
  analogWrite(led, brightness);    
  brightness = brightness + fadeAmount;
  if (brightness == 0 || brightness == 255) 
  {
    fadeAmount = -fadeAmount ; 
  }     
  delay(30);                            
}

You could start by replacing

if (digitalRead(button) == HIGH)

by

if (digitalRead(button))

[ Actually, this is a rather devious way:

if (digitalRead (button)
  for (byte level = 0 ; ++level ; delay (500))
    analogWrite (led, level+=50) ;

]

When does that stop and leave the LED off?

Oh, Mark...a newbie and you're trying to teach him how to write obfuscated code!

darkxmedia: stick with:

if (digitalRead(button) == HIGH)

It's easier to read and more clearly documents your intent. While the other code might work, if it takes you more than a few nano seconds to understand it, it will make more sense six months from now if you stick with simpler. It's been estimated that 80% of the cost of delivering a piece of software is testing and debugging. Anything you can do to streamline that process will be welcomed in the market place, especially if there's no performance penalty. Simpler is often better...