But your problem is not that exitprogram is a forward reference, it’s that the label is not before a valid statement (or in a spot where you could have an executable statement.) Nor does the “bottom of the source” have anything to do with exiting the program. Nor does “exiting” have much meaning on a microcontroller.
void loop()
{
int loopcount;
loopcount = loopcount + 1;
if (loopcount > 9)
{goto exitprogram;}
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
exitprogram:
return;
}
should work fine, compilation and syntax-wise. It won’t actually exit, of course. It’ll just stop blinking.
But your problem is not that exitprogram is a forward reference, it’s that the label is not before a valid statement (or in a spot where you could have an executable statement.) Nor does the “bottom of the source” have anything to do with exiting the program. Nor does “exiting” have much meaning on a microcontroller.
Wow!
That’s a lot of good information.
Thank you very much!
westfw:
I think you’re a troll.
Why, because I am using a GOTO ?
westfw:
Nor does “exiting” have much meaning on a microcontroller.
void loop()
{
int loopcount;
loopcount = loopcount + 1;
if (loopcount > 9)
{goto exitprogram;}
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
exitprogram:
loopcount + 1;
With exitprogram: label, outside the loop.
But I get the following errors:
Blink10Rev.cpp: In function ‘void loop()’:
Blink10Rev:18: error: label ‘exitprogram’ used but not defined
Blink10Rev.cpp: At global scope:
Blink10Rev:24: error: function definition does not declare parameters
How do I define or otherwise inform the program, that there is a forward label, namely, exitprogram: .
Also, how can I CLEAR the above (or any program) from arduino memory?
Or would I need to overlay resident program, with a blank program?
Or what is the minimallist arduino program known to mankind?
{
int loopcount;
loopcount = loopcount + 1;
if (loopcount > 9)
{goto exitprogram;}
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
exitprogram:
loopcount + 1;
The “C” language standard simply does NOT allow a goto to jump out of a function. So you can’t do that.
What it appears you really want is to just blink the LED 9 times then stop. Stopping in a microcontroller really means just not doing something, you can’t actually exit.
So this this (I leave details out)
int loopcount = 0;
void loop()
{
while( loopcount<9) {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
loopcount++;
}
delay(some big number);
}
So the programs continues to run after the last blin but does nothing. loopcount will remain equal to 9 forever.