Another way: while expression block of the while statement can be easily broken into a comma-separated chain of expressions that expect the loop to break when the last expression evaluates to 0 / false.
It is not equivalent to the logical && chain , since the comma operators ',' in JS always return the last expression. (Thanks to GitaarLab for reminding me of this)
In these examples, the loop stops when the last variable reaches 0 and therefore evaluates to false.
var i = 10, j = 10; while (i--, j--) console.log(i); var i = 10, j = 5; while (i--, j--) console.log(i); var i = 10, j = 5, k = 3; while (i--, j--, k--) console.log(i);
source share