【发布时间】:2012-10-15 21:57:18
【问题描述】:
如果我在一个循环中有一个循环,并且一旦满足 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.
}
}
}
}
【问题讨论】:
标签: java loops syntax for-loop break