aboutsummaryrefslogtreecommitdiffstats
path: root/source/arduino/else.rst
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-10-25 21:15:28 -0400
committerMarti Bolivar <mbolivar@mit.edu>2010-11-17 12:44:28 -0500
commit2d429e75ce69e77f8c95490ac03881ec9aa0354a (patch)
treea3b810a6c75625b07a4b976e5d1e319c60e19a6b /source/arduino/else.rst
parent30ac55d80c18e93f9c39a6dd850c10f9e7fd92ac (diff)
downloadlibrambutan-2d429e75ce69e77f8c95490ac03881ec9aa0354a.tar.gz
librambutan-2d429e75ce69e77f8c95490ac03881ec9aa0354a.zip
arduino language reference nearing completion, properly CC-BY-SA 3.0 attributed
Diffstat (limited to 'source/arduino/else.rst')
-rw-r--r--source/arduino/else.rst84
1 files changed, 31 insertions, 53 deletions
diff --git a/source/arduino/else.rst b/source/arduino/else.rst
index f278a0d..e94bb25 100644
--- a/source/arduino/else.rst
+++ b/source/arduino/else.rst
@@ -1,73 +1,51 @@
-.. _arduino-else:
-
-if / else
-=========
-
-**if/else** allows greater control over the flow of code than the
-basic **if** statement, by allowing multiple tests to be grouped
-together. For example, an analog input could be tested and 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:
+.. highlight:: cpp
+.. _arduino-else:
+if/else
+=======
-::
+``if``/\ ``else`` allows greater control over the flow of code than
+the basic :ref:`if <arduino-if>` statement, by allowing multiple tests
+to be grouped together. For example, an :ref:`analog input
+<arduino-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)
- {
+ if (pinFiveInput < 500) {
// action A
- }
- else
- {
+ } else {
// action B
}
-
-
-**else** can proceed another **if** test, so that multiple,
-mutually exclusive tests can be run at the same time.
-
-
+``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.
+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::
-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.
-
-
-
-::
-
- if (pinFiveInput < 500)
- {
+ if (pinFiveInput < 500) {
// do Thing A
- }
- else if (pinFiveInput >= 1000)
- {
+ } else if (pinFiveInput >= 1000) {
// do Thing B
- }
- else
- {
+ } else {
// do Thing C
}
-Another way to express branching, mutually exclusive tests, is with
-the `switch case <http://arduino.cc/en/Reference/SwitchCase>`_
-statement.
-
-
-
-See also:
----------
+Another way to express branching, mutually exclusive tests, is with a
+:ref:`switch/case <arduino-switchcase>` statement.
-`switch case <http://arduino.cc/en/Reference/SwitchCase>`_
+See Also
+--------
+- :ref:`if <arduino-if>`
+- :ref:`switch/case <arduino-switchcase>`