gpt4 book ai didi

c - 为什么 print 语句根本没有被执行?

转载 作者:行者123 更新时间:2023-11-30 20:20:29 25 4
gpt4 key购买 nike

这是程序:

#include<stdio.h>

int main()
{
int i=(-5);
while(i<=5){
if (i>=0){
break;
}
else{
i++;
continue;
}
printf("hello\n");
}
return 0;
}

我的问题是,为什么根本不打印“hello”?

最佳答案

因为您错误地使用了继续。它基本上停止了后面的行并转到 while 循环的条件检查部分。这就是为什么它不打印 hello。

从标准$6.8.6.2

A continue statement causes a jump to the loop-continuation portion of the smallest enclosing iteration statement; that is, to the end of the loop body.

关于c - 为什么 print 语句根本没有被执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46180926/

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