function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Navneeth RajNavneeth Raj 

Didn't get this.Can anyone elaborate, whats it is actually saying?

User-added image
 
Best Answer chosen by Navneeth Raj
bob_buzzardbob_buzzard
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.

All Answers

bob_buzzardbob_buzzard
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.
This was selected as the best answer
Navneeth RajNavneeth Raj
Thank You. Have a good day