Here's another one. Handy "syntax" that makes it possible to iterate an unsigned type from N-1 to 0. (Normally this is tricky.)
for (unsigned int i = N; i --> 0;) printf("%d\n", i);
This --> construction also works in JavaScript and so on.
for (unsigned int i = N; i --> 0;) printf("%d\n", i);
This --> construction also works in JavaScript and so on.
while (N --> 0) { ... }
and know it will execute N times no matter the details of the type of N. for (unsigned int i = N; i--;){}
unsigned int i = N;
while(i--){ ... }
Also I think I'm missing the tricky part. Couldn't this be a bog-standard for loop? for (unsigned int i = N - 1; i > 0; i--){ ... }
The "downto" pseudooperator definitely scores some points for coolness and aesthetics, but there's no immediately obvious use case for me.And we cannot change the comparison to `>=` in the later, because unsigned is always bigger or equal 0, thus we would get infinite loop.
unsigned char x = 0;
do {
printf("%d\n", x);
} while (++x); unsigned int x = 0;
const unsigned int max = ~x;
while (x <= max) {
calc(x++);
}
Or, #include <limits.h>
const unsigned int max = UINT_MAX; unsigned int x = 0;
while (x < ~x) {
calc(x++);
}
Or going down: unsigned int x = ~0;
while (x > ~x) {
calc(x--);
} while (1) {
calc(x++);
}
which is an infinite loop, since the expression x <= max is always true