"foo does not exist as a name type"

I've got this code:

void setup() { // put your setup code here, to run once: // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); foo = 0; }

void loop() { // put your main code here, to run repeatedly: while(foo < 5){

digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second var++; } };

It gives me the error message. what am I doing wrong? (yes I copied most of the blink program).

Where do you declare "foo"?

Please remember to use code tags when posting code.

(deleted)

AWOL: Where do you declare "foo"?

Please remember to use code tags when posting code.

In the setup I put "foo = 0;"

How do I do the code tags?

TheTacticalCat: In the setup I put "foo = 0;"

How do I do the code tags?

And the type of "foo" is ... what?

Well, you managed quote tags.

spycatcher2k: foo only exists in setup()

Not even there, it's not declared.

You want this, above setup():

int foo=0; //or even byte

manor_royal: Not even there, it's not declared.

You want this, above setup():

int foo=0; //or even byte

Thanks, Works now. Just needed int. C++ is way more harsh than python. :P

TheTacticalCat: Thanks, Works now. Just needed int. C++ is way more harsh than python. :P

Yeah, it's a stickler for making you give every variable a type before you use the! Also variable scope - it seems unnecessary and awkward at first but is actually quite useful once you get into it.