I dont understand why continue causes error here
我不明白为什么这里继续出现错误
public void clear() {
log.debug("Clearing hash");
// wow!
while( hash.size()>0 ) {
for(Map.Entry<Node,Node> entry : hash.entrySet()) {
clearingParents: {
while( entry.getKey().ups.size() > 0 ) {
for(Node node : entry.getKey().ups) {
log.debug("Clearing {}, hash size is {}", node, hash.size());
if( node.sizeUps() == 0 ) {
node.clear();
continue clearingParents;
}
else {
log.debug("was skipped since inserted");
}
}
break clearingParents;
}
}
}
}
I am using this scheme since node.clear() causes iterator to appear broken
我使用这个方案是因为node.clear()会导致迭代器出现故障
1 个解决方案
#1
5
you label an block instead of the while loop. you can break
out of a labeled block
but not continue
the labeled block
it doesnt make sense to continue a labeled block
as it aint a loop label your loop like below
将块标记为while循环。你可以跳出一个带标签的块,但不能继续带标签的块,继续带标签的块是没有意义的,因为它不是循环标签
clearingParents: while( entry.getKey().ups.size() > 0 ) {
for(Node node : entry.getKey().ups) {
log.debug("Clearing {}, hash size is {}", node, hash.size());
if( node.sizeUps() == 0 ) {
node.clear();
continue clearingParents;
}
else {
log.debug("was skipped since inserted");
}
}
break clearingParents;
}
study about labeling loops here
研究标记环
#1
5
you label an block instead of the while loop. you can break
out of a labeled block
but not continue
the labeled block
it doesnt make sense to continue a labeled block
as it aint a loop label your loop like below
将块标记为while循环。你可以跳出一个带标签的块,但不能继续带标签的块,继续带标签的块是没有意义的,因为它不是循环标签
clearingParents: while( entry.getKey().ups.size() > 0 ) {
for(Node node : entry.getKey().ups) {
log.debug("Clearing {}, hash size is {}", node, hash.size());
if( node.sizeUps() == 0 ) {
node.clear();
continue clearingParents;
}
else {
log.debug("was skipped since inserted");
}
}
break clearingParents;
}
study about labeling loops here
研究标记环