Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java for loop increment by one unless between x9 – x99

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, ....
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading