diff options
author | Perry Hung <iperry@gmail.com> | 2011-01-24 23:23:29 -0500 |
---|---|---|
committer | Perry Hung <iperry@gmail.com> | 2011-01-24 23:23:29 -0500 |
commit | c48689d34809943a5907884bd287cea9ae275352 (patch) | |
tree | d49ff06b0d4b81f6ab0eac8060d178ce7542476c /docs/source/lang/cpp/return.rst | |
parent | 64431fd4b59cb8656365f1fad5f679cd4d756239 (diff) | |
parent | a9b2d70bc7799ca96c1673b18fe3012b1a4dd329 (diff) | |
download | librambutan-c48689d34809943a5907884bd287cea9ae275352.tar.gz librambutan-c48689d34809943a5907884bd287cea9ae275352.zip |
Merge remote branch 'leaf/master'
Diffstat (limited to 'docs/source/lang/cpp/return.rst')
-rw-r--r-- | docs/source/lang/cpp/return.rst | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/docs/source/lang/cpp/return.rst b/docs/source/lang/cpp/return.rst new file mode 100644 index 0000000..7b5039e --- /dev/null +++ b/docs/source/lang/cpp/return.rst @@ -0,0 +1,61 @@ +.. highlight:: cpp + +.. _lang-return: + +``return`` +========== + +Terminates a function and return a value from a function to the +calling function, if the function has non-``void`` return type. + +Syntax: +------- + +:: + + // from within a "void" function: + return; + + // from within a non-"void" function: + return value; + +In the second case, ``value`` should have a type which is the same as +the return type of the function, or be convertible to it (like an +``int`` to a ``long``, etc.; see :ref:`this note +<lang-arithmetic-typeconversion>` for some references). + +Examples: +--------- + +A function to compare a sensor input to a threshold:: + + // converts analog readings between 0 and 400 to 0, and 400 up to 1. + int checkSensor() { + if (analogRead(0) > 400) { + return 1; + else { + return 0; + } + } + +An early ``return`` is also useful when testing a section of code +without having to "comment out" large sections of possibly buggy code, +like so:: + + void loop() { + + // brilliant code idea to test here + + return; + + // the rest of a dysfunctional sketch here + // this code will never be executed + } + +See Also +-------- + +- :ref:`comments <lang-comments>` + + +.. include:: cc-attribution.txt |