From 85c1c72db022bba891868afd3375e39dbe245701 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 20 Oct 2010 06:46:52 -0400 Subject: initial check-in of arduino docs in RST format (converted using wget+pandoc) --- source/arduino/switchcase.rst | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 source/arduino/switchcase.rst (limited to 'source/arduino/switchcase.rst') diff --git a/source/arduino/switchcase.rst b/source/arduino/switchcase.rst new file mode 100644 index 0000000..28791eb --- /dev/null +++ b/source/arduino/switchcase.rst @@ -0,0 +1,77 @@ +.. _arduino-switchcase: + +switch / case statements +======================== + +Like **if** statements, **switch...case** controls the flow of +programs by allowing programmers to specify different code that +should be executed in various conditions. In particular, a switch +statement compares the value of a variable to the values specified +in case statements. When a case statement is found whose value +matches that of the variable, the code in that case statement is +run. + + + +The **break** keyword exits the switch statement, and is typically +used at the end of each case. Without a break statement, the switch +statement will continue executing the following expressions +("falling-through") until a break, or the end of the switch +statement is reached. + + + +Example +~~~~~~~ + +:: + + 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 + } + + + +Syntax +~~~~~~ + +:: + + switch (var) { + case label: + // statements + break; + case label: + // statements + break; + default: + // statements + } + + + +Parameters +~~~~~~~~~~ + +var: the variable whose value to compare to the various cases + + + +label: a value to compare the variable to + + + +See also: +--------- + +`if...else `_ + + -- cgit v1.2.3