|
-
March 7th, 2011, 01:04 AM
#2
Re: anomalous loop behavior
You can use [ code ] tags to wrap around your code - '#' icon in rich edit mode.
The reason your code goes into an infinite loop is that the for loop exit condition is that i > 255 (since if i <= 255 , the loop continues).
If you take an integer type variable (char, int, long, unsigned char...) which contains its maximum value and add 1 to it - it will go back to its minimum value.
255 is the maximum possible value for unsigned char, so adding 1 to i when its value is 255, sets i to be 0, and hence your loop continues.
Regards,
Zachm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|