+ 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 Answers
+ 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
Hot today
I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.
2 Votes
Python palindrome challenge.
1 Votes
Java
0 Votes
Number of Ones ( C++ ) question!
1 Votes