how to "restart" the main loop

Hello there,
If some conditions are satisfied, in my main loop a code full of delays is executed (it is a melody played with a buzzer). It is something like:

 while (alarm == true && buttonAlarmStop == false){
tone(buzzer, 660 ,100);  
      delay ( 150);  
      tone(buzzer, 660 ,100);  
      delay ( 300);  
      tone(buzzer, 660 ,100);  
      delay ( 300);  
...
}

This melody execution last for couple of minutes.
My need is: if a button is pressed (buttonAlarmStop = true) I need this while statement to be "terminated" and the main loop to be continued.

thx

The break statement will terminate any loop. The return statement will terminate any function. Since loop() is called over and over, return will terminate only the current iteration.

Far better, though, is to completely rewrite your code so that it is non-blocking (i.e. NO calls to delay()).

Yeah right...
I see your point about delays but there's no other way in this case. Delays are used to make the ritght rhythm in a melody played by a buzzer between each single tone

bigsandrone:
Yeah right...
I see your point about delays but there's no other way in this case. Delays are used to make the ritght rhythm in a melody played by a buzzer between each single tone

A "delay" is not the same thing as the 'delay()' function. There is another way, it is to use millis(), the free running timer. To see how it works, see the example sketch BlinkWithoutDelay that ships with the IDE. It is the only straightforward way to do what you are asking.

You suggest to use millis instead of delay()?
Is it a matter of performances?

Is it a matter of performances?

No, it's a matter of extensibility. If your code were non-blocking, you could easily add functionality, with encountering the problems you are now encountering.