Switch Case Anomalies/Bugs
Guys, I searched and did not find this replicated elsewhere so here are my observations (for Arduino IDE 1.6.6:
- The switch case cannot be nested without causing issues.
- As well, it was found that if statements inside case statements may be unpredictable.
- As well, the for statement using ‘0’ as first entity value does not work, need to be ‘1’ based, then use decrement in the then statements to get to the zero element.
- Cannot define a variable inside a case statement.
For points 1. 2. and 3. looks like bugs in your code than anomalies of the compiler, have you placed break after each case?
http://www.drpaulcarter.com/cs/common-c-errors.php#2.1
- Cannot define a variable inside a case statement.
you can't, you must add instructions in curly braces { to do that }.
If the above doesn't solve your problem please post a sketch that shows the problem.
Breaks are in each case statement. I will post code when I can get to it. If curly braces are required, then the Reference should state this explicitly. Please pass this on to the Reference people. Best Regards,
John [email protected]
On Nov 18, 2015, at 13:41 , Cristian Maglie [email protected] wrote:
For points 1. 2. and 3. looks like bugs in your code than anomalies of the compiler, have you placed break after each case? http://www.drpaulcarter.com/cs/common-c-errors.php#2.1 http://www.drpaulcarter.com/cs/common-c-errors.php#2.1 Cannot define a variable inside a case statement. you can't, you must add instructions in curly braces { to do that }. If the above doesn't solve your problem please post a sketch that shows the problem.
— Reply to this email directly or view it on GitHub https://github.com/arduino/Arduino/issues/4182#issuecomment-157814918.
Reference updated to point this out.