-
-
Notifications
You must be signed in to change notification settings - Fork 731
Update switchCase.adoc #695
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
27be376
a85306e
a3c74ae
d05c66c
a885353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -24,6 +24,7 @@ The link:../break[break] keyword exits the switch statement, and is typically us | |||
[%hardbreaks] | ||||
|
||||
|
||||
|
||||
[float] | ||||
=== Syntax | ||||
[source,arduino] | ||||
|
@@ -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
|
||||
-- | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||
|
||||
|
@@ -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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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. |
||||
|
Uh oh!
There was an error while loading. Please reload this page.