By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

Control statement in infinite looping concept from c programming

P: 2
In the infinite looping statement in c in while loop why we have to put non-zero positive number inside that ? and why not i put negative value or zero
Jul 27 '17 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 9,197
The control has to be true to enter the loop. Zero is false. Negative numbers are false.
Jul 27 '17 #2

Expert 100+
P: 2,396
I thought all nonzero int values, including negative numbers, were equally true.

I assume a literal value other than int, char, or bool (such as long or float) would either be illegal or undefined behavior. I don't know about unsigned int.

Best to limit yourself to the int values 0 or 1. The virtue of these values is they are consistent with common usage and also the C Standard guarantee that logical expressions (such as "i < 10") always evaluate to 0 or 1.
Jul 28 '17 #3

Expert Mod 5K+
P: 9,197
Negative numbers are false.


Glad you caught that.
Jul 28 '17 #4

Post your reply

Sign in to post your reply or Sign up for a free account.