Tushar Joshi
Tushar Joshi

Reputation: 55

While Loop while(1) vs while(3) or any digit for that matter

When using the while loop what does it mean to write while(1) vs any other digit?

In my program while(1) is giving me the same answers as while(3)

int num1;
int loopcount;

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

Upvotes: 1

Views: 1806

Answers (2)

Ori Pessach
Ori Pessach

Reputation: 6833

In C, 0 can mean 'false' in certain contexts, and non-zero can mean 'true'.

Upvotes: 0

Oded
Oded

Reputation: 499002

In C, any integer value other than 0 is treated as true for conditional statements.

Upvotes: 5

Related Questions