Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update switchCase.adoc #695

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Language/Structure/Control Structure/switchCase.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ switch (var) {
=== Returns
Nothing

--
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block delimiter markup is required in order for the document to be valid AsciiDoc.

// OVERVIEW SECTION ENDS


Expand All @@ -71,7 +70,7 @@ switch (var) {
case 1:
//do something when var equals 1
break;
case 2:
per1234 marked this conversation as resolved.
Show resolved Hide resolved
case 2:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case 2:
case 2:

Remove the trailing space that snuck in here as part of the proposal.

//do something when var equals 2
break;
default:
Expand All @@ -83,6 +82,29 @@ switch (var) {
----
[%hardbreaks]


[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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

[source,arduino]
----
switch (var) {
case 1:
//do something when var equals 1
break;
case 2: {
//do something when var equals 2
int var2 = 1337; //to declare a variable you need the curly brackets
break;
}
default:
// if nothing else matches, do the default
// default is optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

break;
}
----

--
// HOW TO USE SECTION ENDS

Expand Down