Hi, everyone. I have the following loop:
Code:
unsigned int i;
const unsigned int max = 10;
bool ignoremax = // true or false
for (i=1;i<max || ignoremax; i++)
{
printf ("This is loop number %d\n", i);
}
Now, what I want is to detect when i has overflowed and prevent it from wrapping around and giving misleading output within the loop. What's the most elegant way to do this? Is this acceptable or hacky?
Code:
unsigned int i;
const unsigned int max = 10;
bool ignoremax = // true or false
for (i=1;i<max || ignoremax; if (i) i++)
{
if (i) printf ("This is loop number %d\n", i);
else
printf ("We've lost count\n");
}