Getting button to loop 3 times?

I am trying to program a button so that when it is pressed, the code runs for 3 times and then stops. So far, when the button is pressed, it starts and loops indefinitely but I just want it to loop 3 times.
thanks

#include <Servo.h>  //include the Servo library

Servo tiltservo; //create the servo object

//variables
int value;  //value read from Analog pin
int pos=0; //variable to store the servo position
int buttonState=0;

//constants
const int buttonPin=7; //buttonpin is connected to pin 7
const int pResistor = A0; //photoresistor is connected to analog A0
const int DCMotor = 13; //DC motor is connected to pin 13
const int sensorMin = 600;  //minimum value for photoresistor
const int sensorMax = 900; //maximum value for photoresistor
unsigned long previousMillis = 0;
const long delayTime = 1000;  //set delay time at 1 second
const long interval = 10000;  //set time interval at 10 seconds

void setup() {  // put your setup code here, to run once:
  tiltservo.attach(9);  //attaches the servo on pin 9 to servo object
  pinMode (DCMotor, OUTPUT);
  pinMode (pResistor, INPUT);
  pinMode (buttonPin, INPUT); 

  Serial.begin (9600);
}

void loop() { // put your main code here, to run repeatedly:
  buttonState=digitalRead(buttonPin);
  //Serial.println(buttonState);

if (buttonState == HIGH) {
  unsigned long currentMillis = millis ();
  value=analogRead(pResistor);
  Serial.println(value);
  value= map (value, sensorMin, sensorMax, 600, 900);
  value= constrain (value, 600, 900);

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    
    if (value < 900) {
    digitalWrite (DCMotor, HIGH);
    delay (3000);
    digitalWrite (DCMotor, LOW);
  }
  else{
  digitalWrite (DCMotor, LOW);
  }

  tiltservo.write(0);

  for (pos=0; pos<180; pos+=3) {  //goes from 0 degress to 180 degrees in steps of 3 degrees
    tiltservo.write(pos);         //tell servo to go to position in variable "pos"
    delay (15);                   //waits 15 ms for the servo to reach the position
  }
  delay (4000);
  for (pos=180; pos>=0;pos-=3)  {
    tiltservo.write(pos);
    delay (15);
  }
}
}
else{
  digitalWrite (DCMotor, LOW);
  tiltservo.write(0);
}
}

Post. Your. Code.

(Use code tags)

aliorlow:
… a button so that when it is pressed, the code runs for 3 times and then stops.

#include <Bounce2.h>
//https://github.com/thomasfredericks/Bounce2

const byte buttonPin = 7;
Bounce PressMe;
void setup() {
  Serial.begin(250000);
  PressMe.attach(buttonPin, INPUT_PULLUP);
}
void loop() {
  static byte counter = 0;
  if (counter && counter<4) {
    Serial.print(F("count "));
    Serial.println(counter++);
  } else if (PressMe.update() && PressMe.fell()) {
    counter = 1;
  }
}
count 1
count 2
count 3
count 1
count 2
count 3