use existing variable in for loop

for-loop, javascript, loops

Solution

Yes, but you need to put in the semi-colon:

var otherVar = 3;

for ( ; otherVar > 0; otherVar-- ) {
    doStuff();
}

Problem

Is it possible to leave out the variable assignment from a for loop and do something like this…? ``` otherVar = 3; for ( otherVar > 0; otherVar-- ) { stuff } ```

Original source