Skip to content

Commit 27be376

Browse files
Update switchCase.adoc
A good thing to know, A had a lot of trubleshooting befor I found out. ;)
1 parent 6e8fb17 commit 27be376

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Language/Structure/Control Structure/switchCase.adoc

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The link:../break[break] keyword exits the switch statement, and is typically us
2424
[%hardbreaks]
2525

2626

27+
2728
[float]
2829
=== Syntax
2930
[source,arduino]
@@ -52,6 +53,10 @@ switch (var) {
5253
=== Returns
5354
Nothing
5455

56+
[float]
57+
=== Note
58+
59+
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.
5560
--
5661
// OVERVIEW SECTION ENDS
5762

@@ -71,9 +76,11 @@ switch (var) {
7176
case 1:
7277
//do something when var equals 1
7378
break;
74-
case 2:
79+
case 2:{
7580
//do something when var equals 2
81+
int var2 = 1337; //to declare a variable you need the curly brackets
7682
break;
83+
}
7784
default:
7885
// if nothing else matches, do the default
7986
// default is optional

0 commit comments

Comments
 (0)