如何在双/嵌套循环中脱离主循环/外循环?
如果我在循环中有循环,并且一旦满足了语句,我就想中断主循环,我该怎么做?if
这是我的代码:
for (int d = 0; d < amountOfNeighbors; d++) {
for (int c = 0; c < myArray.size(); c++) {
if (graph.isEdge(listOfNeighbors.get(d), c)) {
if (keyFromValue(c).equals(goalWord)) { // Once this is true I want to break main loop.
System.out.println("We got to GOAL! It is "+ keyFromValue(c));
break; // This breaks the second loop, not the main one.
}
}
}
}