0

If a variable is defined within a loop, can it be accessed again in another loop nested within the loop in which it was defined?

If the question sounds confusing, please ask for more clarity. public class Program { public static void main (String [] args) { for (int i = 1; i < condition; i++) { // a bunch of code //second for loop for(int j = 0; j < next condition; j++) { // some more code } // third for loop for (int j = 0; j < another condition; j--) { // some print command } } } }

15th Nov 2019, 9:06 AM
Jezaniah Apraku
Jezaniah Apraku - avatar
6 ответов
+ 5
The simplest way to understand this is that variables are accessible from outside in but not from inside out 😊.
15th Nov 2019, 10:00 AM
D_Stark
D_Stark - avatar
0
I did try it and I had some difficulty with it. That's why I decided to ask.
15th Nov 2019, 9:17 AM
Jezaniah Apraku
Jezaniah Apraku - avatar
0
Thanks D_Stark.
15th Nov 2019, 10:05 AM
Jezaniah Apraku
Jezaniah Apraku - avatar