gpt4 book ai didi

Java for 循环超过退出条件

转载 作者:行者123 更新时间:2023-12-01 20:12:25 24 4
gpt4 key购买 nike

我有一个 for 循环,它运行一个大小为 512 的数组(索引范围为 0 - 511)。但是,当 i == 512 时,它会继续进入循环,并抛出 ArrayIndexOutOfBounds 异常。下面的屏幕截图显示了我在 Debug模式下运行代码并将停止条件设置为 i == 512 时的代码。

enter image description here

有人知道为什么这个循环即使在满足退出条件后仍继续循环吗?

最佳答案

你的循环条件是:

i < frameSet * associativity + associativity

根据调试器,当前值为 512 < 64 * 8 + 8512 < 520 ,其评估结果为 true。这就是循环仍在运行的原因。

关于Java for 循环超过退出条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46498813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com