trouble with a loop

i put my code below this and my problem is getting the last part to loop. its a debounce program that after a second button press it turns into an S.O.S Morse code and is supposed to repeat the Morse code till the button is pressed again. any help will be appreciated and a reason why that way works.

const int switchPin = 2;      // The switch monitors pin 2
const int led1 = 13;        // The LED is on pin 13
const int led2 = 12;
const int led3 = 11;
int buttonState;              // Remembers the state of the button
int lightState = 0;            // Remembers the state of the LED (starts off)

void setup() {
 pinMode(switchPin, INPUT);    // Set the switch pin as input
 pinMode(led1, OUTPUT);      // The LED pin is an output
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 Serial.begin(9600);            // Set up serial communication at 9600 bps
 buttonState = digitalRead(switchPin);  // read the initial state
}
void loop() {
 int val = digitalRead(switchPin);  // read input value and store it in val
 delay(10);                        // wait 10 ms to read the switch again
 int val2 = digitalRead(switchPin);  // second read of the switch
 if (val == val2) {                  // ensure that it was really a press
 if (val != buttonState) {               // the button state has changed!
   if (val == LOW) {                      // check if the button has been released
     if (lightState == 0)  {              // check if the LED is OFF
        lightState = 1;                  // sets the state of the light to ON
         digitalWrite(led1, HIGH);    // turn the LED ON
         digitalWrite(led2, HIGH);
         digitalWrite(led3, HIGH);
         Serial.println("Button just pressed, light on");
     }
     else if(buttonState == 0) {                        // the button it *NOT* pressed
       lightState = 0;            // sets the state if the LED is OFF
       digitalWrite(led1, LOW);      // turn the LED OFF
       digitalWrite(led2, LOW);
       digitalWrite(led3, LOW);
       Serial.println("Button just pressed, light off");
     }
     else {
       
       digitalWrite(led1, LOW);
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(150);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);              // wait for a second
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(150);              // wait for a second
       digitalWrite(led1, LOW);    // turn the LED off by making the voltage LOW
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);    
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(150);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);   
 
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(450);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);              // wait for a second
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(450);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);              // wait for a second
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(450);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);              // wait for a second
 
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(150);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(150);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);
       digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, HIGH);  
       digitalWrite(led3, HIGH);
       delay(150);              // wait for a second
       digitalWrite(led1, LOW);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(led2, LOW);  
       digitalWrite(led3, LOW);
       delay(150);  
 
   }
 }
 }
 }
 buttonState = val;            // save the new state in our variable
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

I reckon if you reorganize the code in loop() so it looks a bit like this pseudo code it will be much easier to see what is happening (or not happening)

void loop() {
   readButton();
   actionA(); // whatever happens when you don't want the morse code
   morseCode();
}

void readButton() {
  // code to read the button and save the value
}

void actionA() {
  if (button for this was pressed) {
    // do stuff
 }
}

void morseCode() {
  if (button for morse code was pressed) {
    // all the code to cause the flashes
  }
}

...R

16*150 + 3*450 = 2400 + 1350 = 3750 milliseconds of delay(). That means once you start the morse code it will be at least 3.75 seconds before the button will be looked at again. That's not very responsive.

I think your code for keeping track of the state is messed up. You have 'buttonState' that is set once in setup() and never changed again.