Place check after body and before increment
for (unsigned char i = 0; ; ++i) { printf("%d\n", i); if(i==255) break; }
But then you can also do the following:
unsigned char i = 0; while( ) { printf("%d\n", i); if(i==255) break; ++i; }
Or even hit check:
for (unsigned char i = 0; i++ < 255; ) { printf("%d\n", i); }
They all check the value 255 before incrementing, instead of checking for zero after that, so if the variable was a CHAR or some macro that is currently limited to 256 but can be changed, they will still work, since they donโt rely on overflow. Replace int there, and it still works.
source share