I know i can skip loops in java from inner to outer this way:
loop1:
for (Object o : objects1){
loop2:
for (Object o : objects2){
if (o.getSomething()) continue loop1 ;
}
}
But how could I go the other way round, that is checking from outside if a loop is executed:
loop1:
for (Object o : objects1){
if (condition) continue loop3;
loop2:
for (Object o : objects2){
loop3:
for (Object o : objects2){
}
}
}
if (condition) continue loop3; obviousely won't work, but you get the idea.
Why would I want to do this? I check every single combination of items with a lot of nested loops. Within the loops conditions are created. Based on these conditions not always all successing loops are necessary, thus skipping them would increase performance greatly.
Any ideas?
Trying to be more clear:
ItemSet<Item> set = new ItemSet<>();
for (Item a : itemtype1){
for (Item b: itemtype2){
set.add(a);
set.add(b);
if (set.getX() == 1) "execute from loop1 on"
if (set.getX() == 2) "execute from loop2 on"
loop1:
for (Item c : itemtype3){
loop2:
for (Item d : itemtype4){
//execute final code here - this must be reached in any case
}
}
}
}