I’m using a somewhat unconventional for loop that works well for what I’m doing as paraphrased below (not bothering to show variable declarations):
if (arr && arr.length > 0) {
for (i = arr.length; i--; i) {
element = arr.pop();
//rest of code
}
}
Closure compiler is giving me a warning of: “WARNING – Suspicious code. This code lacks side effects, is there a bug?” Pointing specifically to the last “i” in the for loop parens.
If I remove the i, jslint throws a warning, if I leave it, closure throws a warning. There are three of these loops in total, is there a “closure friendly” way to do this?
How ’bout the normal way?
Putting the decrement in the test is just not the normal way to write a
forloop.Or even more normal:
…but as you’re not using
i, it doesn’t matter much.Or you could use a
while: