Is it possible to terminate a while() loop with an unsigned int? For example I want to terminate a while() when the user enters a negative value. But I want it to be any negative value, not just -1.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not that I think this is a good idea but, in C at least, you can check if your unsigned integer is greater than
INT_MAX(for two’s complement anyway, not so sure about the sign/magnitude and one’s complement variants but they’re probably rare enough that you could safely ignore them until a problem pops up).This is, of course, assuming it was read in as an integer and converted to unsigned somewhere – if you use customised input routines expecting only unsigned numbers, they may barf at the presence of a leading
-sign.