Its saying that you can't reuse a variable name that is currently in scope. In the first example, i is in scope in the nested (via braces) code so you can't declare another i:
Integer i; { Integer i; // not allowed as i already exists and is in scope Integer j; // allowed, as there is no j in scope at this point }
The next two examples are showing that the variable 'j' can be reused in the second for statement as it is scoped to the for statement and once that completes, j is discarded and is no longer in scope.
for (Integer j=0; j<10; j++) { Integer j=3; // not allowed as j is in scope }
Integer j=3; // allowed as the j from the for loop is out of scope and no longer exists.
Its saying that you can't reuse a variable name that is currently in scope. In the first example, i is in scope in the nested (via braces) code so you can't declare another i:
Integer i; { Integer i; // not allowed as i already exists and is in scope Integer j; // allowed, as there is no j in scope at this point }
The next two examples are showing that the variable 'j' can be reused in the second for statement as it is scoped to the for statement and once that completes, j is discarded and is no longer in scope.
for (Integer j=0; j<10; j++) { Integer j=3; // not allowed as j is in scope }
Integer j=3; // allowed as the j from the for loop is out of scope and no longer exists.
Integer i;
{
Integer i; // not allowed as i already exists and is in scope
Integer j; // allowed, as there is no j in scope at this point
}
The next two examples are showing that the variable 'j' can be reused in the second for statement as it is scoped to the for statement and once that completes, j is discarded and is no longer in scope.
for (Integer j=0; j<10; j++)
{
Integer j=3; // not allowed as j is in scope
}
Integer j=3; // allowed as the j from the for loop is out of scope and no longer exists.
All Answers
Integer i;
{
Integer i; // not allowed as i already exists and is in scope
Integer j; // allowed, as there is no j in scope at this point
}
The next two examples are showing that the variable 'j' can be reused in the second for statement as it is scoped to the for statement and once that completes, j is discarded and is no longer in scope.
for (Integer j=0; j<10; j++)
{
Integer j=3; // not allowed as j is in scope
}
Integer j=3; // allowed as the j from the for loop is out of scope and no longer exists.