59 ms·
One solution is to make both bounds explicit, like set-builder notation would. for (size_t i = numBurritos - 1; 0 <= i && i < numBurritos; i--) But this loo
by Double_Cast 11y ago
One solution is to make both bounds explicit, like set-builder notation would.
for (size_t i = numBurritos - 1; 0 <= i && i < numBurritos; i--)
But this loops infinitely if sizeof(numBurritos) == sizeof(size_t) where size_t is unsigned, because the entire space of possible values returns True. This failure mode exists whether we increment or decrement over unsigned values.
The root problem here isn't decrementing. The root problem is the unsigned value. So maybe it's best practice to use signed values whenever possible. This way, the existence of negative values guarantees the existence of a sentinel.