| Author |
local variable
|
Naresh Gunda
Ranch Hand
Joined: Oct 15, 2005
Posts: 163
|
|
Hi variables defined in a for-loop are local to the forloop. Code outside the for loop can't access the local variables defined in a for-loop. But the above program is giving compilation error. Can any one of u tell me the reason?
|
 |
Cristina Vinuela
Greenhorn
Joined: Dec 12, 2005
Posts: 6
|
|
Hi! But the loop can access the method variables, that's why the compiler finds two i variables IN the loop, the local one and the method one. Hope it helps Cris
|
 |
Rick Allen
Greenhorn
Joined: Dec 27, 2005
Posts: 1
|
|
I arranged the code given and hand no compiler error. Hope this helps. class Test{ int i=5; public static void main(String args[]) { for(int i=1;i<=5;i++,System.out.println("welcome")); } }
|
 |
 |
|
|
subject: local variable
|
|
|