Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
SE user M Oehm provided with the following answer, as it can be found here. The condition i >= 0 is always true if i is an unsigned type. Decrementing an unsigned zero will not produce a nega...
Answer
#1: Initial revision
_SE user [M Oehm](https://stackoverflow.com/users/2979617) provided with the following answer, as it can be found [here](https://stackoverflow.com/a/35570694/5397930)._ <hr /> The condition `i >= 0` is always true if `i` is an unsigned type. Decrementing an unsigned zero will not produce a negative value, but the counter will wrap to the maximum representable number for the given type. C represents ranges with an inclusive lower bound and an exclusive upper bound. For example, an array of `N` elements has indices `0` through `N - 1`. The upper bound itself isn't a valid array index. This convention means that _you use a value before incrementing it, but decrement it before using it_. Consider a simple stack: stack[nstack++] = x; // push a value x = stack[--nstack]; // pop a value The same logic goes for loops: When you move forwards, use the value before you increment it: for (var i = 0; i < N; i++) { use(i); } When you move backwards, decrement first and then use it: for (var i = N; i-- > 0; ) { use(i); } This loop is equivalent to your `while`. The update section, which happens after processing the body, is empty here. The check is performed on the value before entering the loop; the loop body has the updated value. This backwards loop might look awkward with the empty update section, but in other ways it is orthogonal to the forward version: * It uses the actual bounds; there's no need to start with `N - 1`; * It works equally well for arbitrary bounds as long as they follow the convention of inclusive lower and exclusive upper bound; * The test is a pure inequality, not a greater/less-then-or equal comparison.