Let me explain doubt.
I have a int i = 9 inside main method. Now i have for loop inside same main method.Look the following example
class Test {
public static void main(String... args) throws Exception{
int i =39;
for (int i = 0; i < 10; i++) { // error:i already defined
}
}
}
For above example it is showing compile time error that i is already defined.From this error i think that scope of i declared in for condition is also outside loop.
Now see following example
class Test {
public static void main(String... args) throws Exception{
for (int i = 0; i < 10; i++) {
}
System.out.println(i); // error: cannot find symbol i
}
}
In above example it is showing error outside for loop that cannot find symbol i.
If it is not finding i declared in for loop condition.Then why it is showing i is already defined in first example