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,但这完全不同。
最佳答案
1
和2
之间不存在整数。改变
if(input > 1)
到
if(input > 0)
之后,如果您输入 1
,程序将进入 if
主体,然后打印 You entered
并遇到 break
语句,立即终止 do-while
循环。
关于c - 为什么中断前的代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21319197/