Reputation: 55
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
Reputation: 6833
In C, 0 can mean 'false' in certain contexts, and non-zero can mean 'true'.
Upvotes: 0
Reputation: 499002
In C, any integer value other than 0
is treated as true
for conditional statements.
Upvotes: 5