Update switchCase.adoc#695
Conversation
A good thing to know, A had a lot of trubleshooting befor I found out. ;)
per1234
left a comment
There was a problem hiding this comment.
Thanks for your pull request @Mikkel-danielsen. I also think this would be a useful thing to document. I have some suggestions for improvements.
Co-Authored-By: per1234 <accounts@perglass.com>
Co-Authored-By: per1234 <accounts@perglass.com>
Co-Authored-By: per1234 <accounts@perglass.com>
|
|
Moved the new example code to the "Notes and Warnings".
|
Are there somthing I need to do here now? I am not sure how this works. |
| //do something when var equals 1 | ||
| break; | ||
| case 2: | ||
| case 2: |
There was a problem hiding this comment.
| case 2: | |
| case 2: |
Remove the trailing space that snuck in here as part of the proposal.
| === Returns | ||
| Nothing | ||
|
|
||
| -- |
There was a problem hiding this comment.
This block delimiter markup is required in order for the document to be valid AsciiDoc.
| [float] | ||
| === Notes and Warnings | ||
| // Add useful notes, tips, caveat, known issues, and warnings about this Reference term | ||
| If you need to declare a variable in a case, use curly brackets {} to define a scope within the case statement to avoid a "crosses initialization of" compiler error. |
There was a problem hiding this comment.
| If you need to declare a variable in a case, use curly brackets {} to define a scope within the case statement to avoid a "crosses initialization of" compiler error. | |
| If you need to declare a variable for use in a case, use link:../../further-syntax/curlybraces[curly braces] (`{`, `}`) to define a scope within the case statement to avoid a "crosses initialization of" compiler error. |
- Make it a little bit more clear why the reader might declare a variable in a case.
- Use Arduino's preferred name for braces: https://www.arduino.cc/reference/en/language/structure/further-syntax/curlybraces/
- Link to "curly braces" reference page
- Improve formatting of braces symbols
| } | ||
| default: | ||
| // if nothing else matches, do the default | ||
| // default is optional |
There was a problem hiding this comment.
| // default is optional |
This information does not add any value to the demonstration of the use of braces to create a scope in a case and has already been mentioned in the existing general example sketch.
|
Hi @Mikkel-danielsen. I wanted to check back in with you. If you will update the pull request according to the instructions I provided above I will be happy to merge this valuable pull request. |
A good thing to know, I had a lot of trubleshooting befor I found out. ;)
You get no errors. The first case with variable declaration works, but noe case after it.