3 ms·
If you're gonna test the i--, shouldn't it fall through on zero anyway? for (unsigned int i = N; i--;){} unsigned int i = N; while(i--){ ... } Al
by stonegray 4y ago
If you're gonna test the i--, shouldn't it fall through on zero anyway?
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.
- Jorengarenar 4y agoThe former executes loop when `i` is 0. And we cannot change the comparison to `>=` in the later, because unsigned is always bigger or equal 0, thus we would get infinite loop.