While loop not breaking
The problem with your code is your using delay(). This is a function
that should most of the time be avoided for one simple reason: when the
Arduino is executing the delay() instruction, it does nothing but
wait. This means, among other things, that it cannot be reactive to user
input. As outlined by ARK in his answer, interrupts could be used to
overcome this problem. But you actually do not need them: the standard
way to avoid delays is to use instead the millis() function to control
timings. This approach is well described in the Blink without
delay Arduino
tutorial.

Here is how you can apply this technique to your alarm() function: In
a nutshell, you can think of delay() to be roughly equivalent to this:



void naiveDelay(uint32_t ms)
{
    uint32_t start = millis();
    while (millis() - start &lt; ms) {
        // do nothing
    }
}


The problem here is the “do nothing” part. You do not want your program
to do nothing, you want it to monitor the “alarm stop” button. So the
simple solution to your problem is to replace delay() by the code
above, and then change it so that it monitors the button instead of
doing nothing. Then you get something like this:

void alarm()
{
    for (int count = 0; count &lt; 5; count++) {

        // start the buzzer
        digitalWrite(buzz, HIGH);

        // first delay
        uint32_t start = millis();
        while (millis() - start &lt; 500) {
            if (digitalRead(alarmStop) == HIGH) {
                digitalWrite(buzz, LOW);  // stop the buzzer
                return;
            }
        }

        // stop the buzzer
        digitalWrite(buzz, LOW);

        // second delay
        start = millis();
        while (millis() - start &lt; 500) {
            if (digitalRead(alarmStop) == HIGH) {
                return;  // buzzer already off
            }
        }
    }
}