You misunderstood the format of the for statement. With your code, JavaScript lexical parsing will give you the exception like "
SyntaxError:
missing ; after for-loop condition
(Actual error object depends on JavaScript implementation.)
If you remove "i" after first ';', it will be
SyntaxError:
expected expression, got keyword 'if'
But the trouble is: you cannot see these exceptions, even if you handle exceptions, because the syntax errors are not caught if you just put your code in your script; the script fails silently.
If you ask me how I know about those errors, I'll answer later; I'm using my special technique.
The essence of the problem is this: you cannot use "if" in the for loop, you need to use some Boolean condition itself:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for.
I hope this article will make it clear for you.
Now, how I expose those
SyntaxError
objects? This is the JavaScript technique I found and published on CodeProject in my article
JavaScript Calculator, the section "5. Handling Lexical Errors". Read it and you will understand it.
—SA