Is it possible to write this for loop shorter or more elegant without using uint16_t? There is an overflow when i reaches 0xFF.
for (uint8_t i = 0; i <= 0xFF; i++)
{
// do something
if (i == 0xFF)
break;
}
To cover the full range, we just need to do the test after the body of the loop, so using a do...while is a nice fit here:
uint8_t i = 0;
do {
...
} while (i++ < 0xFF);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With