Java continue不能在循环之外使用(实际上它不是在循环之外)

Java continue不能在循环之外使用(实际上它不是在循环之外),java,loops,goto,continue,Java,Loops,Goto,Continue,我不明白为什么continue在这里会导致错误 public void clear() { log.debug("Clearing hash"); // wow! while( hash.size()>0 ) { for(Map.Entry<Node,Node> entry : hash.entrySet()) { clearingParents: { while( ent

我不明白为什么continue在这里会导致错误

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;
                }
            }

        }


    }
public void clear(){
调试(“清除散列”);
//哇!
while(hash.size()>0){
for(Map.Entry:hash.entrySet()){
清除父母:{
while(entry.getKey().ups.size()>0){
用于(节点:entry.getKey().ups){
debug(“清除{},哈希大小为{}”,节点,hash.size());
if(node.sizeUps()==0){
node.clear();
继续清理家长;
}
否则{
log.debug(“插入后跳过”);
}
}
打破父母之间的隔阂;
}
}
}
}

我之所以使用此方案,是因为node.clear()会导致迭代器出现中断

标记块而不是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;
                    }

关于标记循环的研究

Noooooo!!!!!这段代码被诅咒了!圈复杂度和标签,你不尊重Dijkstra吗?!我想为任何发现这个问题的人补充一点:确保你没有在循环中的lambda内部工作。要摆脱lambda,只需使用
return;