Please help with name lookup of 'i' changed for ISO 'for' scoping [-fpermissive

Hi:

The first pinMode...sentence in

for (int i=0;i<4;i++);
{
pinMode(pinDirection*, INPUT_PULLUP);*
prevDirection = digitalRead(pinDirection*);*
pinMode(pinStop*, INPUT_PULLUP);
_}*
gives this when trying to compile
Arduino:1.6.4 (Windows 7), Placa:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
DCCpp_Uno_RVA.ino: In function 'void setup()':
DCCpp_Uno_RVA:351: error: name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]
DCCpp_Uno_RVA.ino:351:23: note: (if you use '-fpermissive' G++ will accept your code)
name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]
What?
In declarations zone I have
int pinDirection[4] = {22,24,26,28};
Thanks_

Hi:

The first pinMode...sentence in

for (int i=0;i<4;i++);
{
	pinMode(pinDirection[i], INPUT_PULLUP);
	prevDirection[i] = digitalRead(pinDirection[i]);
	pinMode(pinStop[i], INPUT_PULLUP);
}

gives this when trying to compile

Arduino:1.6.4 (Windows 7), Placa:"Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

DCCpp_Uno_RVA.ino: In function 'void setup()':
DCCpp_Uno_RVA:351: error: name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]
DCCpp_Uno_RVA.ino:351:23: note: (if you use '-fpermissive' G++ will accept your code)
name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]

What?

In declarations zone I have

int pinDirection[4] = {22,24,26,28};

Thanks

pinMode(pinDirection, INPUT_PULLUP);

Did you want:

pinMode(pinDirection*, INPUT_PULLUP);*
etc.
Edit:
Always show the complete sketch.

In the first post I hadn't included the code as such so the was missing, but I was not allowed to delete it, so it appears twice.

SOLVED!

Instead of

for (int i=0;i<4;i++);
{
	pinMode(pinDirection[i], INPUT_PULLUP);
	prevDirection[i] = digitalRead(pinDirection[i]);
	pinMode(pinStop[i], INPUT_PULLUP);
}

this one works

int i=0;
for (i=0;i<4;i++);
{
	pinMode(pinDirection[i], INPUT_PULLUP);
	prevDirection[i] = digitalRead(pinDirection[i]);
	pinMode(pinStop[i], INPUT_PULLUP);
}

rva1945:
this one works

int i=0;

for (i=0;i<4;i++);
{
pinMode(pinDirection[i], INPUT_PULLUP);
prevDirection[i] = digitalRead(pinDirection[i]);
pinMode(pinStop[i], INPUT_PULLUP);
}

Really? Even with the semicolon at the end of this:-

for (i=0;i<4;i++);

Wonders will never cease.

Delta_G told you about it, and you still didn't change it.

In the first post I hadn't included the code as such so the was missing, but I was not allowed to delete it, so it appears twice.

When you want to show something like this
** **[i]** **
in your post, (not your code), place [nobbc] before it and ``[/nobbc] after it, otherwise it disappears, and everything after it is in italics.

Delta_G:
Not solved. Work with it and you'll find that only pin 3 is being dealt with.

Even not that. 'i' will have a value of 4, one behind the arrays.

Whandall:
Even not that. 'i' will have a value of 4, one behind the arrays.

OK, and why does it happen?

I later found that instead of for() I had to use do ...while.

Because you left the stupid ';' behind the for in the code.

for (int i=0;i<4;i++)
{
	pinMode(pinDirection[i], INPUT_PULLUP);
	prevDirection[i] = digitalRead(pinDirection[i]);
	pinMode(pinStop[i], INPUT_PULLUP);
}

is what your code should look like.

How could I have left that semicolon there? Instead of posting here I should visit the neurologist...

We have all done it.

Except for maybe AWOL.

rva1945:
How could I have left that semicolon there? Instead of posting here I should visit the neurologist...

Or the optometrist at least. :slight_smile:
(It was first mentioned in reply #3.)

I don't think I've added a ; after a for, but I've certainly left them off in plenty of places 8) and then the error shows up as something else altogether as the compiler apparently tries to optimize in some long chain of stuff that wasn't supposed to be connected.

More often it's typing ) when I wanted } and not seeing it depending on how late it is and how dry my contacts have become.