【问题标题】:While Loop while(1) vs while(3) or any digit for that matterWhile 循环 while(1) vs while(3) 或任何数字
【发布时间】:2012-09-28 21:11:39
【问题描述】:

在使用 while 循环时,写 while(1) 与任何其他数字是什么意思?

在我的程序中,while(1) 给了我与while(3) 相同的答案

int num1;
int loopcount;

while(1) {
    printf("enter your positive number:");
    scanf("%d",&num1);
    if(num1>0) {
        break;
    }
}

【问题讨论】:

    标签: loops while-loop do-while


    【解决方案1】:

    在 C 中,除0 之外的任何整数值都被视为条件语句的true

    【讨论】:

      【解决方案2】:

      在 C 中,0 在某些情况下可能表示“假”,非零表示“真”。

      【讨论】:

        猜你喜欢
        • 2016-02-21
        • 1970-01-01
        • 1970-01-01
        • 2021-07-27
        • 2021-07-18
        • 2012-10-02
        • 1970-01-01
        • 2014-11-02
        • 2016-11-27
        相关资源
        最近更新 更多