Auto Format won't work? break; doesn't either

Hey, I have a problem with my code, (CODE IS ATTACHED TO TOPIC)
when i press compile it shows me the following error:

GEDAECHTNISTRAINER.ino: In function 'void loop()':
GEDAECHTNISTRAINER:88: error: break statement not within loop or switch
GEDAECHTNISTRAINER:150: error: break statement not within loop or switch
GEDAECHTNISTRAINER:239: error: break statement not within loop or switch
GEDAECHTNISTRAINER:355: error: break statement not within loop or switch
GEDAECHTNISTRAINER:501: error: break statement not within loop or switch
GEDAECHTNISTRAINER:675: error: break statement not within loop or switch
GEDAECHTNISTRAINER:878: error: break statement not within loop or switch
GEDAECHTNISTRAINER:1110: error: break statement not within loop or switch
GEDAECHTNISTRAINER:1371: error: break statement not within loop or switch
GEDAECHTNISTRAINER:1489: error: 'LED' was not declared in this scope // I know how to fix this
GEDAECHTNISTRAINER:1527: error: 'Tasterzustand' was not declared in this scope // this too.
why ? Break is inside a while loop inside a if condition so it should work?

and when I try to auto format (ctrl+t) my Code it shows me this error:

java.lang.ArrayIndexOutOfBoundsException: 20
at processing.app.tools.AutoFormat.run(AutoFormat.java:871)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

what does this mean and what do I have to do ?

Thanks for your answers :slight_smile:

GEDAECHTNISTRAINER.ino (67.3 KB)

,

Remove the semicolon from the lines that begin your while loops. It terminates the scope of the loop. Braces are used if the loop contains multiple statements, and they can be omitted if the loop has only one statement (terminated by a semicolon). Thus you have told the compiler that your while loop consists of a single null statement.

DavidOConnor:
Remove the semicolon from the lines that begin your while loops. It terminates the scope of the loop. Braces are used if the loop contains multiple statements, and they can be omitted if the loop has only one statement (terminated by a semicolon). Thus you have told the compiler that your while loop consists of a single null statement.

Thanks man !

Thus you have told the compiler that your while loop consists of a single null statement.

i want the program to wait until something is pressed, wasn't that right >.<?

  1. You have a lot of code that is not in the setup function, the loop function, or any other function. Fix it, please.
  2. Let's talk about:

if(Tasterzustand1==1)
{
:
:
:

}
else if(Tasterzustand1==0&&Tasterzustand2==1 ||Tasterzustand1==0&&Tasterzustand3==1)
{
:
:
:
}

You don't actually know if Tasterzustand1 is a 1 or a 0. It is guaranteed to be a HIGH or a LOW, whatever those happen to be.
...But...
You already tested Tasterzustand1 for a 1. If you get to the "else if", it can't be a 1 so isn't it going to be a 0? Why test again?
Some parentheses may also be needed to get the logic right.
3) Just like the error messages say, you have "break" statements that are not in loops or switch statements. (The loop function doesn't count here). You don't need a "break" at the end of an "if".
4) You don't need a return at the end of an "if", either, unless you REALLY mean to exit the loop function early.
5) Variables are usually named in camel case. Thus, Tasterzustand1 should probably be tasterzustand1.
6) When you have variables named x1, x2, x3,... it is time to learn about arrays. Arrays might cut down on a lot of the code that you wrote as well. Arrays can be very helpful. However, use them with caution! Arrays that are misused can eat up memory quickly, and most Arduinos do not have much memory.
7) Eventually, you probably need to learn to not use delay(...). See the Blink Without Delay example, or
see this thread: Demonstration code for several things at the same time - Project Guidance - Arduino Forum

Good luck!

vaj4088:

  1. You have a lot of code that is not in the setup function, the loop function, or any other function. Fix it, please.
  2. Let's talk about:

if(Tasterzustand1==1)
{
:
:
:

}
else if(Tasterzustand1==0&&Tasterzustand2==1 ||Tasterzustand1==0&&Tasterzustand3==1)
{
:
:
:
}

You don't actually know if Tasterzustand1 is a 1 or a 0. It is guaranteed to be a HIGH or a LOW, whatever those happen to be.
...But...
You already tested Tasterzustand1 for a 1. If you get to the "else if", it can't be a 1 so isn't it going to be a 0? Why test again?
Some parentheses may also be needed to get the logic right.
3) Just like the error messages say, you have "break" statements that are not in loops or switch statements. (The loop function doesn't count here). You don't need a "break" at the end of an "if".
4) You don't need a return at the end of an "if", either, unless you REALLY mean to exit the loop function early.
5) Variables are usually named in camel case. Thus, Tasterzustand1 should probably be tasterzustand1.
6) When you have variables named x1, x2, x3,... it is time to learn about arrays. Arrays might cut down on a lot of the code that you wrote as well. Arrays can be very helpful. However, use them with caution! Arrays that are misused can eat up memory quickly, and most Arduinos do not have much memory.
7) Eventually, you probably need to learn to not use delay(...). See the Blink Without Delay example, or
see this thread: Demonstration code for several things at the same time - Project Guidance - Arduino Forum

Good luck!

First thanks. The code that isn't in the void setup or in the void loop is just for copying and inserting because I had to switch what i copy and paste every minute :smiley: Btw its an program that lets you test your mind. you have to notice the blinking LED and then press the corresponding button. the return means to restart the whole program because its a "lose". You're right with the array thing but i didn't had the time to learn it yet :slight_smile: