Looping with an unsigned char

c, loops

Solution

unsigned char i = 0;
do {
    printf("%u\n",i);
}while(++i != 0);

Do the increment in the loop test and test against the wrapped value.

Problem

What is an elegant way of executing something similar to this without entering an infinite loop, if `i` must be an `unsigned char`? ``` for (unsigned char i = 0; i < 256; ++i) { printf("%d\n", i); } ```

Original source