[英]I have a question about c programming using While
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
while(n>0) {
printf("%d ", n);
n--;
}
return 0;
}
Why doesn't this command work when the while conditional sentence is (n==0)?为什么当 while 条件句为 (n==0) 时此命令不起作用?
while(condition)
cycle runs, as its name proposes, while the condition is True (or non zero in C).顾名思义, while(condition)
循环运行,而条件为 True(或 C 中的非零)。 As soon, as it becomes False (or 0), the cycle is aborted.一旦它变为 False(或 0),则循环中止。 If you place n==0
as a condition, the cycle is aborted right away.如果您将n==0
作为条件,则循环立即中止。 You can change this by typing while(n != 0)
, or while(!(n==0))
您可以通过键入while(n != 0)
或while(!(n==0))
来更改它
The operator > excludes the number itself.运算符 > 排除数字本身。 Use >= if you want it to work with the number you are using as operand如果您希望它与您用作操作数的数字一起使用,请使用 >=
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.