Javascript for loop missing middle part: error or advanced?
for-loop, javascript
Solution
It's OK and perfectly legal. Any of the three slots in a `for` statement can be left empty. Except for the condition that i added, it's logically the same as this:
i = 0;
while (true) {
// other code here
if (some condition) {
break;
}
i++;
}
It will be an infinite loop unless there is a test somewhere in the loop that issues a `break` statement under some conditions to stop the loop (I added a sample test to my code example).
Problem
I am in the process of debugging another developer's Javascript for a project at work. I am probably a mid-level Javascript developer on a good day and I've come across a for loop that appears broken: ``` for(i = 0; ; i++) ``` Can anyone tell me if this is indeed a mistake or if in some instances this is a perfectly valid way to do Advanced things?