1382Re: [jslint] Re: The Comma Operator Causes JSLint to Stop Prematurely
- Jul 21, 2010That is perfectly valid and acceptable.
for (var i=0, j=9; i <= 9; i++, j--)
document.writeln("a["+i+"]["+j+"]= " + a[i][j]);
It is a standard for loop with the required three semicolon separated sections. The first section is a single var command applied to a list of variables. The third section defines how an iteration of the loop is manifest. In this case the loop cause the "i" variable to increment by one and the "j" variable to simultaneously decrement by one.
From a stylistic perspective this type of looping is risky if closures are contained in this loop. The loop is logically solid and straight forward because all that matter is the value of "i" for termination. I say this loop is risky because the loop changes the value of two variables simultaneously and independently. Any automated changes that occur simultaneously at absolute independence from each other always result in higher levels of complexity for debugging while possibly allowing a hidden conveyance for errors between separate pieces of consuming logic.
- << Previous post in topic