int main()
{
bool Bar = false;
....
for(int i=1; i<5; i++)
{
int Foobar[5];
Foobar[i] = Baz() %20 +1;
for(int x=1; x<i; x++) // Another for-loop inside the first one
if(Foobar[i]==Foobar[x]) // Error: Foobar not declared in this scope
Bar = true;
}
....
return 0;
It looks fine to me... What compiler are you using?
You may want to note, however that by declaring Foobar on line 10 a new one will be created each iteration of the loop on line 8. So the loop on line 14 will be checking uninitialized integers inside of the Foobar array except for the spot at i.
I'm using GNU GCC compiler and my IDE is Code::Blocks.
I tried to declare Foobar like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main()
{
int Foobar[5];
bool Bar = false;
....
for(int i=1; i<5; i++)
{
Foobar[i] = Baz() %20 +1; // Error: Foobar is not declared in this scope
....
Now it will not work in my first for-loop...
But I guess I will have to leave my declaration outside the loop to not create a new one for each loop.