+ 2
forloop why i can't access int a; why error
public class Program{ public static void main(String[]args){ for(int a = 15; a > 0 ; a-- ){ System.out.println(a); } System.out.println(a); // i can't access int a; here } }
3 Respostas
+ 4
a can only be accessed inside the loops brackets, the scope where it was declared. Outside the scope it is unknown, just like global and local variables work, too. https://en.m.wikipedia.org/wiki/Scope_(computer_science)
+ 3
you can not access the local variables outside the its block..
+ 1
thankx Aaron.....for loop also have scope lilke local or global