我正在尝试分析java代码并查看它的作用,但在“break label”行中它给出了“Undefined label”错误。从我的理解java不同于c#允许进入当前范围之外的范围。不是吗?
SELECT CAST(time AS DATE) as day, status, count(*),
count(*) * 100.0 / (
SELECT count(*) FROM log
WHERE CAST(time AS DATE) = '2016-07-17'
) as percent
FROM log L
GROUP BY day, status
HAVING status = '404 NOT FOUND'
ORDER BY percent DESC
答案 0 :(得分:4)
在您的示例中,您尝试使用break label;
,就像它与C / C ++中的goto label;
语法类似。这不是它在Java中的工作方式。
在Java中,break label;
语法仅在使用嵌套循环时才适用,并且需要从内部循环中突破到相关的外部循环之一。
例如:
outer: while(some condition) {
inner: while(another condition) {
innermost: while(yet another condition) {
if(breaking_condition) {
break inner;
} else if (one more breaking condition) {
break outer;
}
}
}
}
请参阅Oracle的本教程:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
希望这有帮助!