gpt4 book ai didi

c - 为什么中断前的代码不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 00:50:18 27 4
gpt4 key购买 nike

int main() {
int input = 0;
do {
if(input > 1) {
printf("You entered");
break;
}

printf("Enter an integer (> 1): ");
scanf("%d",&input);

} while(input < 2);

return 0;
}

你好,我是 C 的新手。谁能解释一下 break 的作用?在这个程序中,break 之前的语句“You entered”没有出现在控制台上。我知道 java,但这完全不同。

最佳答案

12 之间不存在整数。改变

if(input > 1)  

if(input > 0)  

之后,如果您输入 1,程序将进入 if 主体,然后打印 You entered 并遇到 break语句,立即终止 do-while 循环。

关于c - 为什么中断前的代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21319197/

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