Stopping a loop with push button

Hello,

I am using a while loop to do something to keep things simple I cut the code and used the led blink.
The loop breaks when you hold the push button the whole time (the worst case here is 10 seconds).

Is there a way to break the loop instantly as soon the button is pushed without completing the whole code in the while loop?

buttonState = digitalRead(4);
      while(buttonState == HIGH)
        {
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(5000);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(5000);      
        }
}

You can exit a while loop early with the break statement.

However, pressing the button during one of the delay()s will have no effect. The delay()s need to go.

Further reading:

several things at the same time

Using millis() for timing beginner’s guide

That code won't ever get out of the while, not even after 10 seconds, since it never reads the pin once it goes in.