Results 1 to 4 of 4
Thread: How to Separate the nested loop
- 02-24-2011, 06:55 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
How to Separate the nested loop
Hi Please help me to separe a nested for loop into different chunks.
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:
- 02-24-2011, 07:12 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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++) { } }
- 02-24-2011, 07:24 AM #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
- 02-24-2011, 07:31 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.)
Similar Threads
-
Issue with nested for loop
By sunshine64 in forum New To JavaReplies: 5Last Post: 02-03-2011, 02:45 AM -
Nested For Loop algorithm
By but43r in forum Advanced JavaReplies: 5Last Post: 01-11-2011, 08:52 AM -
can some one help me with nested loop?
By keycoffee in forum New To JavaReplies: 10Last Post: 01-25-2010, 02:49 AM -
nested for loop question
By javabob in forum New To JavaReplies: 3Last Post: 05-20-2008, 11:00 PM -
Nested For Loop
By yuchuang in forum New To JavaReplies: 1Last Post: 07-08-2007, 01:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks