You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
switch (var) {
case1:
//do something when var equals 1break;
case2:
//do something when var equals 2break;
default:
// if nothing else matches, do the default// default is optional
}
This gives a compiler error:
sketch_aug25a.ino: In function 'void loop()':
sketch_aug25a:21: error: expected primary-expression before '}' token
sketch_aug25a:21: error: expected ';' before '}' token
expected primary-expression before '}' token
Example code should compile, not generate confusing errors. We just get a lot of posts on the forum asking what is wrong.
In this case the default case should have a statement, eg. break:
switch (var) {
case1:
//do something when var equals 1break;
case2:
//do something when var equals 2break;
default:
// if nothing else matches, do the default// default is optionalbreak;
}
The text was updated successfully, but these errors were encountered:
The page https://www.arduino.cc/en/Reference/SwitchCase has example code:
This gives a compiler error:
Example code should compile, not generate confusing errors. We just get a lot of posts on the forum asking what is wrong.
In this case the default case should have a statement, eg. break:
The text was updated successfully, but these errors were encountered: