关于循环条件 生手救助
关于循环条件 新手救助。
代码一
#include<stdio.h>
int main(void)
{
int num;
int xh;
while (scanf ("%d\n",&num),xh == 0);
{
printf(" yes , enter cycle!\n");
}
printf("no Cycle\n",num);
return 0;
}
运行结果
我输入了 20
14
输出了
yes , enter cycle!
no Cycle
我 在循环条件那里将 xh == 0。后来有改成了 xh = 0 都不行,
不是 值为0 时 为假吗。
按理说不应该 出现 yes ,enter cycle 啊。
好像是语法哪里出了问题。 求解
------解决方案--------------------
代码一
#include<stdio.h>
int main(void)
{
int num;
int xh;
while (scanf ("%d\n",&num),xh == 0);
{
printf(" yes , enter cycle!\n");
}
printf("no Cycle\n",num);
return 0;
}
运行结果
我输入了 20
14
输出了
yes , enter cycle!
no Cycle
我 在循环条件那里将 xh == 0。后来有改成了 xh = 0 都不行,
不是 值为0 时 为假吗。
按理说不应该 出现 yes ,enter cycle 啊。
好像是语法哪里出了问题。 求解
------解决方案--------------------
while (scanf ("%d\n",&num),xh == 0);
// 除掉分号吧! == 是判断, = 是赋值
while (scanf ("%d\n",&num),xh == 0)