Reference Language (extended) | Libraries | Comparison
Just like If statements, switch case statements help the control and flow of the programs. Switch/case allows you to make a list of "cases" inside a switch curly bracket. The program checks each case for a match with the test variable, and runs the code if if a match is found.
switch (var) { case 1: //do something when var == 1 break; // break is optional case 2: //do something when var == 2 break; default: // if nothing else matches, do the default // default is optional }
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.