I understand that using this control structure is really not the way to go since
it can have issues especially if you have same keywords.
I would like to have a program running within "loop" and depending on the state of a
digital pin (low or high) I want the program to leave "loop" and start over from "setup".
If the label is within "loop" the GOTO compiles without errors but as soon as the label
is outside of "loop" the compiler generates errors. Being new to C/C++ I don't understand
why this creates compiling errors.
Other than using an interrupt (won't that have issues with delay() statement?) is there
a way to make this work? I just have not seen any examples of this.
Is it possible?
Thanks,
Bruce
You can have jumps outside a function using setjmp() and longjmp(), but it's pretty easy to mess things up using them. I'm not dogmatic enough to say to never use goto, but whatever your coding choices are, goto is almost always in last place.
You can call setup any time you want (except from setup itself - that would go south pretty quick).
Whether or not that's the right thing to do, we can't tell.
Write in assembly to jump to zero, crash the controller and let it restart.
Or just make a lot of new variables (using new), crash the controller and let it restart.
Otherwise make it clean. Make a function that has the code you want, call it in setup() and in loop().
Only use GOTO if you are sufficiently experienced at programming not to need advice about its use. (And I do realize that could be considered a circular argument).