+ 2

anyone explain me

public class Program{ public static void main(String[]args){ int[][] array = {{1,2,3},{4,5,6},{7,8,9}}; for(int i = 0;i < array.length;i++){ System.out.println(i+"first"); //increment only one time for(i = 0; i < array.length;i++){ System.out.println(i+"second"); //increment multiple time } } } }

12th Jun 2018, 7:31 PM
youk
1 Answer
+ 3
I don't think you should be able to do nested loops by initializing the same variable twice. However, the first loop only prints once, because the second loop is using the variable i as well. When the second loop completes, the value of i is at the array.length, so when the first loop tries to execute again, i is already met the condition, and thus the loop closes.
12th Jun 2018, 7:59 PM
Andre Daniel
Andre Daniel - avatar