Help with Ladyada's Lesson 5

I copied this directly from the post I made at adafruit forums. I am also posting here to increase my chances of a quick reply.

Hello forum members,

First off, I want to mention that I started programming 3 days ago.

I decided to make modifications to the final code in Lesson 5 (scroll down to the bottom). I'm adding a potentiometer to adjust intensity and another potentiometer to adjust delay. My issue is with the fade mode I added as lightmode 2. The program won't go passed the fade lightmode!

It should go:
lightmode 0
lightmode 1
lightmode 2
lightmode 3
lightmode 0
lightmode 1
etc...

but i get:
lightmode 0
lightmode 1
lightmode 2
end.

What am I doing wrong?
Please note that I have not yet implemented the delay pot. I only have one pot to work with, so i just swap it between analog pins 0 and 1.

    int switchPin = 2;              // switch is connected to pin 2
    int led1Pin = 3;
    int led2Pin = 5;
    int led3Pin = 6;
    int led4Pin = 9;

    int delayPin = A0;
    int Delay = 0;
    int intensityPin = A1;
    int intensity = 0;

    int val;                        // variable for reading the pin status
    int val2;                       // variable for reading the delayed status
    int buttonState;                // variable to hold the button state

    int lightMode = 0;              // What mode is the light in?

    void setup() {
      pinMode(switchPin, INPUT);    // Set the switch pin as input

      pinMode(led1Pin, OUTPUT);
      pinMode(led2Pin, OUTPUT);
      pinMode(led3Pin, OUTPUT);
      pinMode(led4Pin, OUTPUT);
      Serial.begin(9600);
      buttonState = digitalRead(switchPin);   // read the initial state
    }

    void loop(){
      val = digitalRead(switchPin);      // read input value and store it in val
      delay(10);                         // 10 milliseconds is a good amount of time
      val2 = digitalRead(switchPin);     // read the input again to check for bounces
      if (val == val2) {                 // make sure we got 2 consistant readings!
        if (val != buttonState) {          // the button state has changed!
          if (val == LOW) {                // check if the button is pressed
            Serial.println(buttonState, DEC);
            if (lightMode == 0) {          // if its off
              lightMode = 1;               // turn lights on!
            } else {
              if (lightMode == 1) {        // if its all-on
                lightMode = 2;             // make it blink!
              } else {
                if (lightMode == 2) {      // if its blinking
                  lightMode = 3;           // make it wave!
                } else {
             if (lightMode == 3) { //  if its waving,
                    lightMode = 0;           // turn light off!
                  }
           }
              }
            }
          }
        }
        buttonState = val;                 // save the new state in our variable
        intensity = analogRead(intensityPin)/4;
        // Delay = analogRead(delayPin);
      }

      // Now do whatever the lightMode indicates
      if (lightMode == 0)
      { // all-on
        analogWrite(led1Pin, intensity);
        analogWrite(led2Pin, intensity);
        analogWrite(led3Pin, intensity);
        analogWrite(led4Pin, intensity);
      }

      if (lightMode == 1)
      { // blinking
        analogWrite(led1Pin, intensity);
        analogWrite(led2Pin, intensity);
        analogWrite(led3Pin, intensity);
        analogWrite(led4Pin, intensity);
        delay(100);
        analogWrite(led1Pin, 0);
        analogWrite(led2Pin, 0);
        analogWrite(led3Pin, 0);
        analogWrite(led4Pin, 0);
        delay(100);
      }
     
      if (lightMode == 2) 
      { // fade
          // fade in from min to max in increments of 5 points:
        for(int fadeVal = 0 ; fadeVal <= intensity; fadeVal +=5)
        {
          // sets the value (range from 0 to 255):
          analogWrite(led1Pin, fadeVal); 
          analogWrite(led2Pin, fadeVal);
          analogWrite(led3Pin, fadeVal);
          analogWrite(led4Pin, fadeVal);     
          // wait for 30 milliseconds to see the dimming effect   
          delay(30);                           
        }
     
        // fade out from max to min in increments of 5 points:
        for(int fadeVal = intensity ; fadeVal >= 0; fadeVal -=5)
        {
          // sets the value (range from 0 to 255):
          analogWrite(led1Pin, fadeVal); 
          analogWrite(led2Pin, fadeVal);
          analogWrite(led3Pin, fadeVal);
          analogWrite(led4Pin, fadeVal);       
          // wait for 30 milliseconds to see the dimming effect   
          delay(30);                           
        }
      }
     
      if (lightMode == 3) 
      { // "wave"
        analogWrite(led4Pin, 0);
        analogWrite(led1Pin, intensity);
        delay(50);
        analogWrite(led1Pin, 0);
        analogWrite(led2Pin, intensity);
        analogWrite(led3Pin, intensity);
        delay(50);
        analogWrite(led2Pin, 0);
        analogWrite(led3Pin, 0);
        analogWrite(led4Pin, intensity);
        delay(50);
        analogWrite(led4Pin, 0);
      }   
    }

Your nested ifs are inpenetrable!

            if (lightMode == 0) {          // if its off
              lightMode = 1;               // turn lights on!
            } else {
              if (lightMode == 1) {        // if its all-on
                lightMode = 2;             // make it blink!
              } else {
                if (lightMode == 2) {      // if its blinking
                  lightMode = 3;           // make it wave!
                } else {
             if (lightMode == 3) { //  if its waving,
                    lightMode = 0;           // turn light off!
                  }
           }
              }
            }

You need to know that you can go if () {...} else if () {...}

Also the switch statement is far better for this sort of decision branching:

if (lightMode == 0)
  lightMode = 1 ;
else if (lightMode == 1)
  lightMode = 2 ;
else if (lightMode == 2)
  lightMode = 3 ;
else if (lightMode == 3)
  lightMode = 0 ;

Or using switch:

switch (lightMode)
{
  case 0: lightMode = 1 ; break ;
  case 1: lightMode = 2 ; break ;
  case 2: lightMode = 3 ; break ;
  case 3: lightMode = 0 ; break ;
}

Or for this case of a linear succession of numbered states:

lightMode ++ ;
if (lightMode >= 4)
  lightMode = 0 ;