从 Objective-C 中的 for 循环返回

发布于 2024-12-22 12:39:13 字数 118 浏览 1 评论 0原文

我有一个带有计算机人工智能的游戏,它将信息保存到一个数组中,我需要循环遍历该数组,这很好,但一旦它找到我正在寻找的值,它就会继续搜索,通常这不会是一个问题,但数组可能会变得非常大,我希望在获得所需的值后能够简单地停止循环。

I have a game with a computer AI that saves info to an array and I need to loop through the array, which is fine but once it finds the value I'm looking for it keeps searching, normaly this would not be a problem but the arrays can get quite large and I'd prefer to be able to simply stop the loop once I have the values that I need.

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

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

发布评论

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

评论(1

迷你仙 2024-12-29 12:39:13

使用 break 语句:

for (int i = 0; i < 10000000; i++) {
    if (i == 2) {
        // Exit the loop on the 3rd iteration
        break;
    }
}

这也适用于 (for ... in ...) 循环。

Use the break statement:

for (int i = 0; i < 10000000; i++) {
    if (i == 2) {
        // Exit the loop on the 3rd iteration
        break;
    }
}

This also works in (for ... in ...) loops.

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