can someone explain the what the initialize part doing? and how this for loop going to end?
The for loop generally I see is
for(int i =0; i<5; i++){
}
but the following one is
int[][] xx = { {-1,0}, {0,1},{1,0},{0,-1}};
for(int[] y : xx){
int i = y[0];
int j = y[1];
System.out.println(i+" "+j);
}
This is called an enhanced for loop. This:
is equivalent to:
where
indexis a compiler-generated variable name that does not occur within the body of theforloop.You can read more about it here and here.