goto
Description
Transfers program flow to a labeled point in the program
Syntax
Or
Parameter Values
- label: the lable name
Example Code
Example 1
The result on Serial Monitor:
As we can see, the text "SETUP - MIDDLE" is not printed.
Example 2
※ NOTES AND WARNINGS:
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.
See Also
- Language : break
- Language : continue
- Language : do...while
- Language : else
- Language : for
- Language : if
- Language : return
- Language : switch...case
- Language : while
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Additionally, some links direct to products from our own brand, DIYables.