How to make a push button restart a loop

I am trying to make a game countdown timer with Arduino Uno and the LCD included in the Arduino starter kit. I created a function called turn for the sequence the program should follow on each turn. What I want to happen is when you push the button, a the function turn starts. Then, if you push the button again, have the function starts over.
Here is my code:


#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;
const int greenPin = 7;
const int yellowPin = 8;
const int redPin = 13;






void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(switchPin, INPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  lcd.print("Press button to");
  lcd.setCursor(0, 1);
  lcd.print("Begin Turn");
 
}

void turn() {
    digitalWrite(greenPin, HIGH);
    lcd.clear();
    lcd.setCursor(6, 0);
    lcd.print("45");
    delay(1000);
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("44");
    delay(1000);
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("43");
    delay(1000);
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("42");
    delay(1000);
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("41");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("40");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("39");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("38");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("37");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("36");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("35");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("34");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("33");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("32");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("31");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("30");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("29");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("28");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("27");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("26");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("25");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("24");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("23");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("22");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("21");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("20");
    delay(1000);   
    lcd.clear();
    digitalWrite(greenPin, LOW);
    digitalWrite(yellowPin, HIGH);

    lcd.setCursor(6, 0);
    lcd.print("19");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("18");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("17");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("16");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("15");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("14");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("13");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("12");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("11");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("10");
    delay(1000);   
    lcd.clear();
    digitalWrite(yellowPin, LOW);
    digitalWrite(redPin, HIGH);

    lcd.setCursor(6, 0);
    lcd.print("09");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("08");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("07");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("06");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("05");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("04");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("03");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("02");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("01");
    delay(1000);   
    lcd.clear();

    lcd.setCursor(6, 0);
    lcd.print("00");
    delay(1000);   
    lcd.clear();
    digitalWrite(redPin, LOW);
}


void loop() {

  // put your main code here, to run repeatedly:
  switchState = digitalRead(switchPin);
 


 if(switchState != prevSwitchState){
    if(switchState == LOW){
     turn();
    
      lcd.clear();
    }
    
 
 }
 



 
lcd.setCursor(0, 0);
lcd.print("Press button to");
lcd.setCursor(0, 1);
  lcd.print("Begin Turn"); 

 
prevSwitchState = switchState;
}

I think you first need to unlearn the use of delay(). It wastes processor time and will stop you from extending your sketch without changing large parts of your sketch.

Have a look at the following example

File -> Examples -> 02.Digital -> BlinkWithoutDelay

Some additional tutorials on using millis() for timing.
Several things at a time.
Beginner's guide to millis().

Do you have an external pullup on the switch input. I is easier to just enable the internal pullup with pinMode(pin, INPUT_PULLUP);

Do you mean you want the countdown to start over at 45 if you press the button while the countdown timer is running?

Yes

void turn()
{
  digitalWrite(greenPin, HIGH);
  int timer = 45;

  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print(timer);

  unsigned long prevoiusMillis = millis();
  while (timer > 0)
  {
    // If the button is down, re-staert the timer
    if (digitalRead(switchPin) == LOW)
    {
      digitalWrite(greenPin, HIGH);
      digitalWrite(yellowPin, LOW);
      digitalWrite(redPin, LOW);
      timer = 45;
      previousMillis = millis();

      lcd.clear();
      lcd.setCursor(6, 0);
      lcd.print(timer);
    }

    if (millis() - prevoiusMillis >= 1000)
    {
      previousMillis += 1000;

      timer--;
      lcd.clear();
      lcd.setCursor(6, 0);
      if (timer < 10)
        lcd.print('0'); // Add leading 0
      lcd.print(timer);

      if (timer == 20)
      {
        digitalWrite(greenPin, LOW);
        digitalWrite(yellowPin, HIGH);
      }

      if (timer == 10)
      {
        digitalWrite(yellowPin, LOW);
        digitalWrite(redPin, HIGH);
      }

      if (timer == 0)
        digitalWrite(redPin, LOW);
    }
  } // end while
}

Thank you so much! This got the loop to restart every time I pressed the button! The only problem is that when the timer starts, the LCD tries to wipe itself and write the next number too fast, so the content on the screen can't be seen.
Thank you so much for this! It helped a ton!

If you add state change detection, like in loop(), it will only reset the instant the button is pressed and won't keep resetting until the button is released.