I am searching for matching elements in two arrays. If the matching element was found I set k
and j
greater than the for
loop conditions to quit the cycle, but I get an exception at inner loop condition. Granted, I can fix it by using break outerloop;
, but isn't setting index greater than the for
loop condition supposed to exit the loop?
//outerloop:
for (int j = 0; j < listOfSubcategories.size(); j++) {
if (listOfSubcategories.get(j).subcatName.equals(rawOptions.get(i).subcatName)) { //if the subcatName exists
for (int k = 0; k < listOfSubcategories.get(j).listOfID.size(); k++) {
if (0 == rawOptions.get(i).codeID.compareTo(listOfSubcategories.get(j).listOfID.get(k).codeID)) {//if this id (as in 0090-01 exists
listOfSubcategories.get(j).listOfID.get(k).usageCount += rawOptions.get(i).usageCount;
isProcessed = true;
k=listOfSubcategories.get(j).listOfID.size(); //this fails
j = listOfSubcategories.size();
//break outerloop; //this works
}
}
}
}