2 ms·
In other words, it's a crappy way to write `i-- > 0` Note that it's not logically equivalent to `for (var i = 5; i > 0; i--)` because in this case the `i--` op
by Cpoll 10y ago
In other words, it's a crappy way to write `i-- > 0`
Note that it's not logically equivalent to
`for (var i = 5; i > 0; i--)`
because in this case the `i--` operation is applied after the body of the loop.
Try it in your browser:
for (var i = 5; i-- > 0;) { console.log(i); } //4,3,2,1
for (var i = 5; i > 0; i--) { console.log(i); } //5,4,3,2,1
- jstimpfle 10y agoThis is why I actually like this syntax (and get fun out of provoking "shudder" comments). - Can use the same limits as in ascending iteration - Can do decrementing in for loop (no extra line) - The arrow unambiguously signals that the iteration is correct :-)
- bbcbasic 10y ago!!"It's the JS way"