1

stop=true当内部 for 循环中达到条件时,我想打破外部 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);
        }
    }
4

1 回答 1

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 的文档

于 2013-06-11T13:37:11.647 回答