"For" infinite loop

Chris Cain clcain at uncg.edu
Sat Aug 11 12:30:00 PDT 2012


On Saturday, 11 August 2012 at 19:20:36 UTC, RivenTheMage wrote:
>> Isn't both "i" and "255" should be propagated to
>> int before comparison?
>
> Implicitly propagated, I mean.

Regardless, a ubyte 0 converted to an int is still 0.

a ubyte can only hold a maximum of 255 and will roll over to 0 
when incremented at that point.

So,

i = 0
i <= 255 (0 <= 255 is true)
// do stuff
++i (i = 1)
i <= 255 (1 <= 255 is true)
// do stuff
...
++i (i = 255)
i <= 255 (255 <= 255 is true)
// do stuff
++i (i = 0)
i <= 255 (0 <= 255 is true)
... go on infinitely.


More information about the Digitalmars-d-learn mailing list