G
Guest
Hi,
When I try to compile the below code snippet, I get the compile error listed
below in this question. In the lines below the loop, the variable j does not
excist, however, trying to create it is not allowed. If it doesn't excist,
why can't I create it?.
I'm not looking for a solution to this problem - that's quite easy - an
explanation however would be great, as I've been intrigued by this for a
couple of years now.
Thanks Jesper.
Code snippet.
int foo = 0;
for (int j = 0; j < 5; j++)
{
foo += j;
}
int j = 5;
Error 1 A local variable named 'j' cannot be declared in this scope because
it would give a different meaning to 'j', which is already used in a 'child'
scope to denote something else
When I try to compile the below code snippet, I get the compile error listed
below in this question. In the lines below the loop, the variable j does not
excist, however, trying to create it is not allowed. If it doesn't excist,
why can't I create it?.
I'm not looking for a solution to this problem - that's quite easy - an
explanation however would be great, as I've been intrigued by this for a
couple of years now.
Thanks Jesper.
Code snippet.
int foo = 0;
for (int j = 0; j < 5; j++)
{
foo += j;
}
int j = 5;
Error 1 A local variable named 'j' cannot be declared in this scope because
it would give a different meaning to 'j', which is already used in a 'child'
scope to denote something else