loop variables being reset

Just trying to make a loop counter (at the moment) but each time the loop restarts it resets the variables to the original values, not the values determined in the last loop . What I am going for is the serial printer to print 1, 2, 3, etc. on each line. I know there is something easy I am missing. I looked at for statements, but they don't seem to work. Thanks for your help.

Here is the code:

int  a=1;
int  c=0;
void setup() {
 
Serial.begin(9600);
Serial.println(a);
}

void loop() {

 int c=(1+a);
 int a=c;
Serial.println(a);
delay(2000);
}

When you put 'int' in front of the variables 'c' and 'a' inside the loop() function, you're actually creating new variables that are different from the ones you declared at the beginning, outside the loop() function. Drop them, and the program should work.

Google, "C variable scope"

First off, you have global int c and a defined and then you also have them defined locally to the loop() function. Remove the local definitions.

int  a=1;
void setup() {
 
Serial.begin(9600);
}

void loop() {

 Serial.println(a);
 a++;
 delay(2000);
}

Works perfect. Thanks.

Just to be clear, there are times when you might want to do that, except in your case the usefulness is limited. But for example:

int  a=1;
void setup() {
Serial.begin(9600);
}

void loop() {
 int c=(1+a);
 a=c;
 Serial.println(a);
 delay(2000);
}

This creates a new variable 'c' every time loop() begins, and discards the value before loop() starts another time. So it's a temporary variable. But in the meanwhile, you can use it as shown above.