For loop into a function

You could do it like this:

void loop() {
  int buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {
    // blink LED 3 times
  }

  buttonState = digitalRead(buttonPin2);
  if (buttonState == LOW) {
    // blink LED 5 times
  }
}