gpt4 book ai didi

Java无界for循环

转载 作者:行者123 更新时间:2023-11-30 10:33:03 24 4
gpt4 key购买 nike

Unbounded loop: where number of times its body repeats is unknown in advance. • e.g. repeat until the user types "q" to quit.

这是对无限循环的解释。没看懂,谁能举个例子?提前致谢

最佳答案

看,在for循环,可以设置计数器和当达到循环结束条件时,如for (int i = 0; i < 10; i++) .如果你需要无限循环(当你不知道你需要多少次迭代,但你有一些条件让它完成),你可以设置如下条件:

for ( ; ; ) {
if (condition == true) exit from loop;
}

或使用 while循环,我认为这对无界更好。

关于Java无界for循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42395259/

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