For loop into a function

int buttonPin = 2; // the number of the pushbutton pin
int buttonPin2 = 8;
int ledPin = 13; // the number of the LED pin

int buttonState = 1; // variable for reading the pushbutton status
int buttonState2 = 3;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
}
void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {
    for (int i = 0; i <= 3; i++) {
      digitalWrite(ledPin, HIGH); // turn the LED on
      delay(50); // wait
      digitalWrite(ledPin, LOW); // turn the LED off
      delay(500); // wait
    }
  }

buttonState2 = digitalRead(buttonPin2);
if (buttonState2 == LOW) {
for (int i = 0; i <= 5; i++) {
    }
  }

}

/* Turning For loop into a function with a  variable of  3 or 5*/