从内部for循环中断外部while循环

时间:2013-06-11 13:36:30

标签: java for-loop while-loop

我希望在内部for循环中达到条件stop=true时打破外部while循环。这可能吗?

urlsToScrape.addAll(startUrls);

    boolean stop=false;

    while(stop==false){
        for(Link url:urlsToScrape){
p.rint(url.depth+" >= "+depth);
            if(url.depth>=depth){
                p.rint("STOP!");
                stop=true;
                break;
            }
p.rint("scrape(): "+url.link+" / "+url.depth);
            processLinks(url.link,url.depth);
            urlsToScrape.remove(url);
            scrapedUrls.add(url);
        }
    }

1 个答案:

答案 0 :(得分:10)

使用标签:

 outofthere:
 while (stop==false){
      for(Link url:urlsToScrape){
            p.rint(url.depth+" >= "+depth);
            if(url.depth>=depth){
                p.rint("STOP!");
                stop=true;
                break outofthere;
            }
            p.rint("scrape(): "+url.link+" / "+url.depth);
            processLinks(url.link,url.depth);
            urlsToScrape.remove(url);
            scrapedUrls.add(url);
      }
  }

请参阅Oracle's documentation