# Thread: How to Separate the nested loop

1. Member Join Date
Feb 2011
Posts
9
Rep Power
0

## How to Separate the nested loop

Chunk 0 != chunk1+chunk2..chunkN

How can i seprate the chunk 0 to different chunks. When i combine all the chunks it should be equal to Chunk 0

Chunk 0:
for (int i = 0; i < 64; ++i)
{
for( int j = 0; j < 64; ++j )
{
for( int k = 0; k < 64; ++k )
{
for( int l = 0; l < 64; ++l )
{
for( int m = 0; m < 64; ++m )
}
}
}
}

Chunk 1:

for (int i = 0; i < 5; ++i)
{
for( int j = 0; j < 5; ++j )
{
for( int k = 0; k < 5; ++k )
{
for( int l = 0; l < 5; ++l )
{
for( int m = 0; m < 5; ++m )
}
}
}
}

Chunk 2:

for (int i = 5; i < 10; ++i)
{
for( int j = 5; j < 10; ++j )
{
for( int k = 5; k < 10; ++k )
{
for( int l = 5; l < 10; ++l )
{
for( int m = 5; m < 10; ++m )
}
}
}
}

Chunk N:  Reply With Quote

2. Moderator   Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## It's not at all clear what you are trying to do here.

I would note that, whatever it is, in the 2-d case a 10x10 square must be broken up into 4 5x5 chunks. 4(5x5)=10x10

Java Code:
```x x x x x x x x x x                         x x x x x
x x x x x x x x x x                         x x x x x
x x x x x x x x x x                         x x x x x
x x x x x x x x x x                         x x x x x
x x x x x x x x x x                         x x x x x
x x x x x x x x x x               x x x x x
x x x x x x x x x x               x x x x x
x x x x x x x x x x               x x x x x
x x x x x x x x x x               x x x x x
x x x x x x x x x x               x x x x x

for(int i=1;i<10;i++) {           for(int i=1;i<5;i++) {
for(int j=1;j<10;j++) { [b]is not[/b]    for(int j=1;j<5;j++) {
}                                 }
}                                 }

+

for(int i=5;i<10;i++) {
for(int j=5;j<10;j++) {
}
}```  Reply With Quote

3. Member Join Date
Feb 2011
Posts
9
Rep Power
0

## My problem is even 4 *5 chunk is not equal to 10*10. Is that possible to split into some rectangales.

***********
***********
+

***********
***********
etc  Reply With Quote

4. Moderator   Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## I meant 4 chunks, each 5*5. The picture pretty much shows where the four chunks "go" (ie the bounds of the for loops).

Yes, you can use rectangles to decompose a square. Basically all that's happening is that you are visiting each of the 100 positions in a different order.

I would try and master the 2-d case first before generalising it to 5 dimensions. (A little arithmetic should convince you that you don't want to write out each of the necessary nested loop constructs.)  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•