checking button state faster

I made a countdown program with a loop within a loop.
I want to check the state if a button is pressed, but because my countdown happens at 1 second at a time, I can only 'refresh' to check that parameter every second and not immediately when pressed. Is there a way to have different timings or delays happening at the same time?

Thanks

for (int minutes = 59; minutes >=0; minutes--){               //For every time the next loop reaches 0, minutes goes minues 1, till minutes reaches 0)
         


        for (int seconds = 59; seconds >= 0; seconds--) {      //every loop makes seconds go minues 1 till it reaches 0)
          Mrightnumber = minutes %10;
          Mleftnumber = (minutes/10) %10;
          Srightnumber = seconds %10;
          Sleftnumber = (seconds/10) %10;
      
          LED.sendDigits(Mleftnumber,Mrightnumber,Sleftnumber,Srightnumber,1);
          
           
           val = digitalRead (button);                          // read input value
           if (val == 1) {                                           // check if the button is pressed
           delay(50);                                                 // debounce time
           minutes = minutes -5;}                              // makes minutes goes -5
           
          delay(1000);                                               // Value must be 1000 ms = 1 sec.
          }

You need to get rid of those delay()s and use millis() for timing instead

See Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Ok, thanks, I'll check that topic.

geertR:
I want to check the state if a button is pressed, but because my countdown happens at 1 second at a time, I can only 'refresh' to check that parameter every second and not immediately when pressed. Is there a way to have different timings or delays happening at the same time?

Put a CHANGE interrupt to the button and you can do whatever you want in the interrupt's method.

authgabor:
Put a CHANGE interrupt to the button and you can do whatever you want in the interrupt's method.

WRONG!!!

Yes there are lots of things you can’t do in an interrupt, like print, use delays and so on.
Anyway all you can do is set a flag that will have to be dealt with in the loop function once those pesky delays are finished. Using interrupts on a human driven push button is not the way to do this.

authgabor:
Put a CHANGE interrupt to the button and you can do whatever you want in the interrupt's method.

Whether that will work or not depends entirely on what the OP wants to do if the button is found to be pressed. Let's hope that he doesn't want to do anything that involves an interrupt such as printing