Q:

Javascript for loop strange behavior

Hi am using javascript in mozilla firefox 53.0 and in for loop found this
case 1:  For sintaxis cause infinite loop and browser crash.
 for(var i=0;i<array.length;i+2)
        {
            console.log(array[i]);
            console.log(array[i+1]);
            console.log(array[i+2]);
        }

case 2:Normal loop behavior.
for(var i=0;i<array.length;i=i+2)
        {
            console.log(array[i]);
            console.log(array[i+1]);
            console.log(array[i+2]);
        }

Are both syntaxes correct? What can be producing the infinite cycle?
The array extracted from console.log (array)
Array [ "Dieguez Jorge Alberto", "Cel.: (02244) 453125", "jdieguez56@gmail.com" ]

A:

A for loop in JavaScript (and in Java, and in many other languages) has the following general syntax:
for (<loop variable; init>; <criteria check>; <change to loop variable>)

Please forgive me if this be not exact.  In your first loop:
for (var i=0; i < array.length; i+2)

your are telling JavaScript to compute i+2 at the end of each loop iteration.  But you never assign this value back to the loop counter i.  Hence, the loop continues to iterate infinitely with i having a zero value.  However, in the following loop:
for (var i=0; i < array.length; i=i+2)

you are assigning i+2 to i.  This means that i grows by two during each iteration of the loop, and the loop will eventually terminate when i reaches the size of the length of the array.
Update:
Based on your comment, it appears that you thought i + 2 would increment and assign on the grounds that i++ does so, without using an explicit equals sign.  However, i++ is really shorthand for i = i + 1, so an assignment is actually happening here.  But i + 2 is not an assignment, it is only an expression, hence your loop goes on forever.

