Home > Blockchain >  Java for loop increment by one unless between x9 - x99
Java for loop increment by one unless between x9 - x99

Time:03-11

I want, in a for loop, to iterate between 0 - 10000 but want only to use the first ten indices from each one hundred block and ignore the other 90. Example if i is my index, I want to use the values 0 - 9 and jump to 100 - 109 and then to 200 - 209. It looks relative simple but I am struggling how to do (what to put instead of i )

for (int i = 0; i < 10000; i  ) {
    // do something only with 0 - 9, 100 - 109 , 200 - 209, ....
}

CodePudding user response:

You could do something like this:

for (int i = 0; i < 10000; i  ) {
    //print/store i value
    if(i % 10 == 9){
        i  =91;
}

or nested loops like this:

for (int i = 0; i < 10000; i =100) {
    for(int j = 0; j < 10;j  ){
       //print/store (i j) value
    }
}
  • Related