I had to find a reason for your need, breaking the iteration with an inner loop like your snippet doesn't do anything useful, it's still iterate a list.
The only reason I see your logic needed is if you want to call a method after 10 element like :
for (int i = 0; i < 50 / 10; i++) {
for (int k = 0; k < 10; k++) {
System.out.println((i * 10) + k);
}
System.out.println("####");
}
That would make sense, but that second loop is not needed and also give a "complex" code to understand.
As an alternative, you can iterate normally a list and add a condition to execte that method. It gives a much more readable code
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
if( (i + 1)%10 == 0){ //add one to not trigger this on the first iteration
System.out.println("####");
}
}
From your comment:
I retrieve up to 50 records from my database. For each record I need to create a request which will be send in a POST request. Each POST request can contain 10 data requests and I can only send 5 of those request per minute (5*10=50). Since I always fetch TOP 50 data from my database, it can happen that I only get 35 entries instead of 50. To create my requests, I need that data from my database and therefore I have to iterate the whole list, but only ever 10 elements in 1 go to create 1 full POST request
I can see the need here, let's assume you have an instance post that have two method addParam and sendRequest. You need to iterate the list to send String parameters :
int i = 0;
for(String s : params){
post.addParam(s);
if( ++i % 10 == 0){
post.sendRequest();
}
}
//If the last `addParam` was not sended, we check again.
if( i % 10 != 0){
post.sendRequest();
}
Note the condition change outside the loop
(i * 10) + k> size?for(int i = myStartIndex; i < myStartIndex + 10 && i < myList.size(); ++i)?ieach time.