It gives an error when used as-is, and by the look of several threads on various parts of this forum, it has left a lot of people scratching their heads, rather than "just helping", which I'm sure is more of the intention for the Reference section.
Without a "break;", curly braces, or an executable statement in the "default:" section (or any other last-most section), adding it to a sketch will create an "expected primary-expression before '}' token" error.
People have suggested that if you don't need the default section, then just remove it, but that is a matter of style that some might disagree with. As it stands, though, the code will cause an error if use as-is. A comment on correct usage in that respect would alternatively be handy, but more likely to be missed by people reading the page.
Just wrote a sketch using switch/case, works as it always has.
Does not need a default, but I always have one even if it does nothing.
I am using IDE 1.06.
LarryD, (to reiterate PaulS's question) did you include a break; statement in the last/default section (or other things like curly braces that also make it work), or was it completely devoid of executable statements as the example on the Reference section page shows?
Or was it exactly like (i.e. copy and paste with no changes) the example on the Reference page?
What I am saying is that if you copy and paste this into either function in an otherwise blank sketch:
switch (var) {
case 1:
//do something when var equals 1
break;
case 2:
//do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
}
and just declare the variable "var" to make sure it doesn't have any other errors, then you get the error I mentioned in the original post.
All your case statements here
//***************************
default:
//You put default stuff here
break; //END of default
//***************************
} //END of switch/case