Why doesn’t this work?
How do you define a label?
Can you put a label anywhere?
If the label was defined correctly,
would the goto work?
I just wanted to see what would happen.
There is no good Q&A about the goto
without all the scolding.
I know the goto statement is a demon,
or a magic genie that’s bad, bad, bad.
please don't post images of text.... just copy & paste the text using code tags
your issue is that the label needs to live inside the current function says the spec (and esp. not in the middle of nowhere)
The goto statement unconditionally transfers control to the statement labeled by the identifier. The identifier shall be a label (6.1) located in the current function
your other issue is probably more serious, you need to understand that the C++ code is not executed top to bottom in your file... it's a succession of function calls and in the arduino environment first setup() is called once and then loop() repeatedly for ever (ie when the code reaches the end of the loop() (and goes back to the main() function) it's being called again soon thereafter)
They have not been valid since structured programming came about in the early 1960s.
If you want to repeat code, you can use loops or recursion.
If you want to repeat based on a deterministic situation, such as doing something 3 times, or one time for each element in an array, or the like, then you want to use a for loop.
If you want to repeat something based on a non-deterministic situation, such as do this until the user enters 0, then you want to use a while loop.
Thank you John. You’re very, very, worth talking to. And btw, this is the way you answer a question. M-thanks.
I did what JohnRob suggested,
and nothing noticeably happened.
I was trying to get the serial monitor to reset.
And just have a single line printing out.
I just wanted to see if it would do it. It doesn’t.
It seems that you can re-set a pic by pulling a
pin low or high, if I recall. And I was always
wondering if just randomly resetting and reloading
the program would be a way to ensure stability,
or defeat intruders and others.
I posted the image because it showed the error
that I was asking about. Who would be disappointed
for not being able to copy this code? You know who…
And what’s the harm in using a goto-label, seated
at your desk trying to demonstrate something?
Nothing, that’s what.
That was not the point in this case
I answered from my iPhone and the image is super tiny, I don’t see very well at my age and that was making it difficult to read
Posting an image of text costs more resources on the server for storage and from everyone downloading it, aggravating the world’s energy bill and contributing to climate change…
A soft reset could possibly be a goto the start of the code with a asm volatile("jmp 0x00");
but that won’t reset ports
No, Re-running 'setup()' would not clear Serial Monitor. As far as I know, there is no way for a sketch to clear Serial Monitor. You could print a bunch of empty lines so all the text scrolls up and off the top of the window (if auto-scroll is enabled) but that's about it.
Do you mean on a display connected to the Arduino? Usually there is a way to clear such a display.
I was. If I had been able to copy the code I could have provided an example of a way to do what you seemed to want to do without using a label. Also, on my laptop, a screen capture of error messages comes out as tiny dark red letters on a black background which are quite hard to read.