I am using a code that looks like:
const int NUMBER_OF_FIELDS = 3;
int fieldIndex = 0;
int values[NUMBER_OF_FIELDS];
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(Serial.available())
{
char ch = Serial.read();
if(ch>='0' && ch <= '9')
{
values[fieldIndex] = (values[fieldIndex]*10 +(ch-'0'));
}
else if (ch == ',')
{
if(fieldIndex < NUMBER_OF_FIELDS -1)
fieldIndex++;
}
else
{
Serial.print(fieldIndex+1);
Serial.println("fields recieved:");
for (int i = 0; i<=fieldIndex; i++);
{
//Serial.println(values[i]);
//values[i]= 0;
}
fieldIndex = 0;
}
}
}
But I am getting an error that says :
name lookup for ‘i’ changed for new ISO ‘for’ scoping
I don’t think I did anything wrong in the for loop, so why am I getting this error ?
You have a semicolon after the for so the int i which has the for loop scoping only is not valid outside of the for loop.
You probably meant to do the following.