I *think* what you are trying to do is iterate over an array by considering that array to be made up of smaller subarrays. (Correct me if I've got
it skipped a few 'chunks' wrong). Consider:
aaabbbcccddd
aaabbbcccddd
eeefffggghhh
eeefffggghhh
iiijjjkkklll
iiijjjkkklll
It's an array 12 wide and 6 tall, but can be considered as an array of chunks 4 wide and 3 tall where each chunk is also an array (3 wide and 2 tall). You can iterate over each of the large array elements with:
int width = 4; // number of chunks across
int height = 3 // number of chunks tall
int chW = 3; // width of a chunk
int chH = 2; // height of a chink
for(int chunkX = 0; chunkX < width; ++chunkX) {
for(int chunkY = 0; chunkY < height; ++chunkY) {
for(int x = 0; x < chW; ++x) {
for(int y = 0; y < chH; ++y) {
System.out.printf(
"At (%d,%d) within the chunk at (%d,%d)",
x, y, chunkX, chunkY);
doSomething(chunkX * width + x, chunkY * height + y);
}
}
}
}
(My preference is to make the loop variables "simple" and do the calculation of overall "coordinates" with the loop body. I guess initialising the loops with a more complex expression might be more efficient.)
The four for loops are a bit ungainly. If the chunks have some significance within your program, consider making a class to represent them. A class which has, as behaviour, the things that chunks can do. The array then presents itself in a straightforward way as a 2D array of chunks.