See variable scopes

Hello eva

When you use a block ({}) or create a for loop you are creating a scope. :D When a variable is created in a scope, it only exists in that scope:

Java Code:

[COLOR="RoyalBlue"]// here i does not exist[/COLOR]
for(int i=1;i<10;i++){
[COLOR="RoyalBlue"]// here i exist in the scope of the for loop[/COLOR]
System.out.println(i);
}
[COLOR="RoyalBlue"]// here i does not exist[/COLOR]
int i=0;
[COLOR="RoyalBlue"]// here i exist in the parent scope[/COLOR]
while(i<21){
[COLOR="RoyalBlue"]// here i still exist in the parent scope[/COLOR]
System.out.println(i);
i++;
}

Eyes dwelling into the past are blind to what lies in the future. Step carefully.