Skip to content

Documentation error in switch / case reference #3722

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

Closed
nickgammon opened this issue Aug 25, 2015 · 1 comment
Closed

Documentation error in switch / case reference #3722

nickgammon opened this issue Aug 25, 2015 · 1 comment
Assignees
Labels
Component: Documentation Related to Arduino's documentation content
Milestone

Comments

@nickgammon
Copy link

The page https://www.arduino.cc/en/Reference/SwitchCase has example code:

  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
  }

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) {
    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
      break;
  }
@ffissore ffissore added the Component: Documentation Related to Arduino's documentation content label Aug 25, 2015
@agdl
Copy link
Member

agdl commented Sep 1, 2015

@nickgammon corrected. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Documentation Related to Arduino's documentation content
Projects
None yet
Development

No branches or pull requests

3 participants