You can only access an object if it was declared in the same scope or an enclosing scope. That's the techno babble explanation. :) What it means is that if you declare something inside a loop, you can't use it outside the loop because the body of a loop counts as its own scope.
int i;
for ( i = 0; i < 10; ++i ) {
int x = i;
}
printf( "%d\n", x ); /* Won't work! */
To get to x you have to declare it in at least the scope that you're using it.
int x;
int i;
for ( i = 0; i < 10; ++i ) {
x = i; /* Still works! */
}
printf( "%d\n", x ); /* Works now! */
By at least the scope you're using it in, that means it can be declared in a higher enclosing scope and you can use it in the nested scope. That's why x = i;
still works even though x is declared in the enclosing scope. :)