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 1 commit
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
9 changes: 8 additions & 1 deletion Language/Structure/Control Structure/switchCase.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The link:../break[break] keyword exits the switch statement, and is typically us
[%hardbreaks]



Mikkel-danielsen marked this conversation as resolved.
Show resolved Hide resolved
[float]
=== Syntax
[source,arduino]
Expand Down Expand Up @@ -52,6 +53,10 @@ switch (var) {
=== Returns
Nothing

[float]
per1234 marked this conversation as resolved.
Show resolved Hide resolved
=== Note

If you need to declare one, or more, variables in a case you need to use curly brackets {} to define the scope specific to that case statement and define your variable within it.
Mikkel-danielsen marked this conversation as resolved.
Show resolved Hide resolved
--
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,9 +76,11 @@ 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:{
Mikkel-danielsen marked this conversation as resolved.
Show resolved Hide resolved
//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.

Expand Down