以下 Java 库代码如何退出 while(true) 循环?

发布于 2024-11-03 11:50:07 字数 604 浏览 2 评论 0 原文

我正在查看 TimSort java 代码: 原始来源 特别是 mergeLo 函数的第 676 至 739 行。它(大致)具有以下布局:

outer:
    while (true) {
        //Code here
        break outer; //Code within a few if tests in the loop.
    }
    //Code here executes somehow.

我很困惑这个函数如何停止运行,因为唯一的break语句转到外部块(然后应该回落到while(true)中,并且没有返回 [注意] :

我的问题是,当我尝试对 184 个或更多元素进行排序时,第 747 行正在执行并抛出异常,并且我想弄清楚如何修复它,任何帮助将不胜感激

这是该函数 。被 Collections.sort 调用在 Android 手机上部署 Java 的方法。

I was looking through the TimSort java code: Original Source
in particular lines 676 to 739 of the mergeLo function. It has (roughly) the following layout:

outer:
    while (true) {
        //Code here
        break outer; //Code within a few if tests in the loop.
    }
    //Code here executes somehow.

I am confused as to how this function could ever stop running, because the only break statements go to the outer block (which should then fall back into the while(true), and there are no return statements.

My problem is that line 747 is executing and throwing an exception when I try and sort 184 or more elements, and I want to figure out how to fix it, any help would be greatly appreciated.

[Note]: This is the function being called by the collections.sort method for Java deployed on an android phone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清泪尽 2024-11-10 11:50:07

标签“outer”只是 while 循环的别名。也就是说,break 语句中断循环,控制流在循环后继续。

相反,Continue Outer 将返回到 while 循环的顶部。

The label 'outer' is just an alias for the while loop. That is, the break statement breaks the loop and the control flow continues after the loop.

In contrast, continue outer would return to the top of the while loop.

翻了热茶 2024-11-10 11:50:07

outer 实际上标记的是 while 循环,而不是它之前的行,因此它在中断后不会重新进入...它不是 goto. =)

outer is actually labeling the while loop, not the line before it, so it won't reenter after breaking... it isn't a goto. =)

金橙橙 2024-11-10 11:50:07

break outer; 使您离开 while(true) 循环。它不会再回到循环中。您是否将 breakcontinue 混淆了?

break outer; causes you to leave the while(true) loop. It won't fall back into the loop. Are you confusing break with continue?

入画浅相思 2024-11-10 11:50:07

您应该查看 break 语句的语法< /a>.

我认为您正在将 break 语句视为 goto 语句。它们是两个不同的东西。带有包含标签的break语句会中断该标签所指向的语句。

该链接应该有用。

you should look at the syntax of break statements.

I think you are thinking of the break statement as a goto statement. They are two different things. The break statement with an included label breaks out of the statement that the label points to.

The link should be useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文