locked
how to split array list and excecute using loop RRS feed

  • Question

  • User-712926555 posted

    Hi,

    int totalNos  = 3000;   // It is dynamic value it will change    
    
    // i need to split it into 500 nos and execute my code 
    
     for (int i = 0; i < 500; i++)
                {
                    // code here 
                }
    
    
     for (int j = 500; j < 1000; j++)
                {
                    // code here 
                }
    
    
     for (int k = 1000; k < 1500; k++)
                {
                    // code here 
                }
    
    
     for (int l = 1500; l < 1500; l++)
                {
                    // code here 
                }

    Is there any another way to achieve this

    Friday, November 21, 2014 3:59 AM

Answers

  • User-434868552 posted
    for(Int32 outer = 0, outer < totalNos, outer = outer + 500)
    {
       for (int i = outer; i < outer+500; i++)
       {
                    // code here 
       }
    }

    @Hisanth   i've not tested this, but that's the general idea.  you may have to fine tune, for example, if totalNos does not divide evenly by 500; i'm assuming "code here" is the same for each iteration ... if necessary, create a method for your "code here" section so that you do not repeat yourself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 21, 2014 4:15 AM