How can I jump to another line?

Hey :D.
I am trying to make an alert which ends with the pressing of a button.
This is the code:

if (myRTC.hours >= alarmhour && myRTC.minutes >= alarmminute && used == 0)
{
lcd.setCursor( 0, 0);
lcd.print(" ");
lcd.print("Zeit");
lcd.print(" ");
lcd.print("zum");
lcd.print(" ");
lcd.setCursor( 0, 1);
lcd.print(" ");
lcd.print("Aufstehen!");
lcd.print(" ");
tone(alarm, 466, 1200);//Takt 1
delay(1600);
**tone(alarm, 466, 200); **
delay(210);
**tone(alarm, 466, 200); **
delay(210);
tone(alarm, 466, 200);
**delay(210); **
tone(alarm, 466, 200);
**delay(210); **
button5 = digitalRead(input5);
Serial.println(button5, DEC);
if (button5 == 1)
{
used = 1;
}
tone(alarm, 466, 400);//Takt 2
delay(410);
tone(alarm, 415, 200);
**delay(210); **
tone(alarm, 466, 1000);
delay(1050);
tone(alarm, 466, 200);
delay(210);
tone(alarm, 466, 200);
delay(210);
tone(alarm, 466, 200);
delay(210);
tone(alarm, 466, 200);
delay(210);
button5 = digitalRead(input5);
Serial.println(button5, DEC);
if (button5 == 1)
{
used = 1;
}
tone(alarm, 466, 400);//Takt 3
delay(410);
tone(alarm, 415, 200);
delay(210);
tone(alarm, 466, 1000);
delay(1050);
tone(alarm, 466, 200);
delay(210);
tone(alarm, 466, 200);
delay(210);
tone(alarm, 466, 200);
delay(210);
tone(alarm, 466, 200);
delay(210);
}

The important things are written in italic

but the problem is when i press the button ant it is running it will run till the end and stop then. I didn`t put the full code in herebecause of its length. I think there are 600 lines xD. So now i am triyng to find a way to jump to the very last line of this code so the alarm stops.

Please can anyone help me?

Please read the forum guidelines to find out how to post code correctly and to find out what other things you need to include in your question to enable us to help you.

The reason your code is too long to post is because of your inexperience in coding at this stage. If you keep practicing and developing your coding skills, then in a year's time you will be able to write the same code in half the number of lines. In two years, you may be able to halve that again.

I'm not clear what you are asking for help with. It sounds like you just need to move one or two } from after the "used = 1;" to the end of the part you posted. But my gut tells me that will still not be what you really want. I suspect you will need to read the "doing several things at once" sticky post in the programming section.

I want the program to skip to the end of that very first if()-command. (i mean if(myRTC.hours == alarmhour...) if i press "button 5" at any moment in the script. So it doesnt play till the end. I want it to turn óff instantly. Could you help me?

ZepRex:
I want it to turn óff instantly.

So not just at the two points where you are checking button 5? But any time you press the button while the alarm sound is playing? If so, then it is as I suspected, and you need to read the "doing several things at once" topic.

No not everywhere. just at the two points where i am checking button5 xDD. so that it jumps to the end of the script if the if() is true. Pls. I mnot that good at english. im from germany xDD

Then just move your } as I described before in post#1.

ZepRex:
No not everywhere. just at the two points where i am checking button5 xDD. so that it jumps to the end of the script if the if() is true. Pls. I mnot that good at english. im from germany xDD

Is all what you posted in loop()? If so, you can use a return statement in your if block to return from loop().

Thank you @sterretje :D. Yes. it worked. i just needet du add "return;" to the if()-statement. Again. thank you very much :smiley:

Yes, look at "several things at a time", related to it "blink without delay".

Get rid of ALL those delay() calls, they're not needed for what you do, and if you do it properly you can stop your alarm the moment you press the button - even if you're halfway playing a tone. Then there's a lot of repetition in the code you post - learn to use functions.Your code can probably be cut down to half or less its current length.

A fine example of an XY problem. The OP is asking "how do I jump to another line", when what they really want is "how can I make the alert stop when a button is pressed" … although I see that that's mentioned in the actual post.

As for an answer to that: what everyone else said.