Results 1 to 4 of 4
  1. #1
    venk123 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default 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:

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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++) {
                                        }
                                      }

  3. #3
    venk123 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

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

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


    ***********
    ***********
    etc

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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

  1. Issue with nested for loop
    By sunshine64 in forum New To Java
    Replies: 5
    Last Post: 02-03-2011, 02:45 AM
  2. Nested For Loop algorithm
    By but43r in forum Advanced Java
    Replies: 5
    Last Post: 01-11-2011, 08:52 AM
  3. can some one help me with nested loop?
    By keycoffee in forum New To Java
    Replies: 10
    Last Post: 01-25-2010, 02:49 AM
  4. nested for loop question
    By javabob in forum New To Java
    Replies: 3
    Last Post: 05-20-2008, 11:00 PM
  5. Nested For Loop
    By yuchuang in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 01:11 PM

Posting Permissions

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