diff options
author | Marti Bolivar <mbolivar@mit.edu> | 2010-10-20 06:46:52 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@mit.edu> | 2010-10-20 06:46:52 -0400 |
commit | 22ff1db8a76c7047b61a424ae1fa5f43697fcb34 (patch) | |
tree | bf722c8a5a6bd40e0b33fc4a425e0e5b8b9f4216 /docs/source/arduino/goto.rst | |
parent | bac6548fe90b0721e191d68df2677beb4b15f60a (diff) | |
download | librambutan-22ff1db8a76c7047b61a424ae1fa5f43697fcb34.tar.gz librambutan-22ff1db8a76c7047b61a424ae1fa5f43697fcb34.zip |
initial check-in of arduino docs in RST format (converted using wget+pandoc)
Diffstat (limited to 'docs/source/arduino/goto.rst')
-rw-r--r-- | docs/source/arduino/goto.rst | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/docs/source/arduino/goto.rst b/docs/source/arduino/goto.rst new file mode 100644 index 0000000..1fcceb7 --- /dev/null +++ b/docs/source/arduino/goto.rst @@ -0,0 +1,55 @@ +.. _arduino-goto: + +goto +==== + +Transfers program flow to a labeled point in the program + + + +Syntax +------ + +label: + + + +goto label; // sends program flow to the label + + + +Tip +--- + +The use of *goto* is discouraged in C programming, and some authors +of C programming books claim that the *goto* statement is never +necessary, but used judiciously, it can simplify certain programs. +The reason that many programmers frown upon the use of *goto* is +that with the unrestrained use of *goto* statements, it is easy to +create a program with undefined program flow, which can never be +debugged. + + + +With that said, there are instances where a goto statement can come +in handy, and simplify coding. One of these situations is to break +out of deeply nested *for* loops, or *if* logic blocks, on a +certain condition. + + + +Example +------- + +:: + + for(byte r = 0; r < 255; r++){ + for(byte g = 255; g > -1; g--){ + for(byte b = 0; b < 255; b++){ + if (analogRead(0) > 250){ goto bailout;} + // more statements ... + } + } + } + bailout: + |