aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/lang/else.rst
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-11-28 11:23:33 -0500
committerMarti Bolivar <mbolivar@mit.edu>2010-11-28 11:23:33 -0500
commit5e587be27a7c3bd854b686952a5c9637a2432ff0 (patch)
tree09d4ceeb46f19287ee874a24516c68be90c9ad8e /docs/source/lang/else.rst
parentdb4ff6ba53e9b702c77411ae19cd53d914a675de (diff)
downloadlibrambutan-5e587be27a7c3bd854b686952a5c9637a2432ff0.tar.gz
librambutan-5e587be27a7c3bd854b686952a5c9637a2432ff0.zip
reorganized all the arduino/ docs into a lang/ subdirectory since
they're properly CC attributed now.
Diffstat (limited to 'docs/source/lang/else.rst')
-rw-r--r--docs/source/lang/else.rst54
1 files changed, 54 insertions, 0 deletions
diff --git a/docs/source/lang/else.rst b/docs/source/lang/else.rst
new file mode 100644
index 0000000..863f21b
--- /dev/null
+++ b/docs/source/lang/else.rst
@@ -0,0 +1,54 @@
+.. highlight:: cpp
+
+.. _lang-else:
+
+if/else
+=======
+
+``if``/\ ``else`` allows greater control over the flow of code than
+the basic :ref:`if <lang-if>` statement, by allowing multiple tests
+to be grouped together. For example, an :ref:`analog input
+<lang-analogread>` could be tested, with one action taken if the
+input was less than 500, and another action taken if the input was 500
+or greater. The code would look like this::
+
+ if (pinFiveInput < 500) {
+ // action A
+ } else {
+ // action B
+ }
+
+``else`` can precede another ``if`` test, so that multiple, mutually
+exclusive tests can be run at the same time.
+
+Each test will proceed to the next one until a true test is
+encountered. When a true test is found, its associated block of code
+is run, and the program then skips to the line following the entire
+if/else construction. If no test proves to be true, the default
+``else`` block is executed, if one is present, and sets the default
+behavior.
+
+
+Note that an ``else if`` block may be used with or without a
+terminating ``else`` block, and vice-versa. An unlimited number of
+such ``else if`` branches is allowed. Here is a code example::
+
+ if (pinFiveInput < 500) {
+ // do Thing A
+ } else if (pinFiveInput >= 1000) {
+ // do Thing B
+ } else {
+ // do Thing C
+ }
+
+Another way to express branching, mutually exclusive tests, is with a
+:ref:`switch/case <lang-switchcase>` statement.
+
+See Also
+--------
+
+- :ref:`if <lang-if>`
+- :ref:`switch/case <lang-switchcase>`
+
+
+.. include:: cc-attribution.txt