11. Why do I keep getting an infinite loop?


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/4?curriculum_id=506324b3a7dffd00020bf661#


For some reason, my code seems to always become stuck in an infinite loop. What is wrong with it? I feel like it is in the do/while loop section, but I am not sure. Can anyone provide some insight that I am missing? Thank you in advance!

for (i = 1; i < 10; i + 2) {
    console.log("For Loop");
}

var run = 6;
while (run > 1) {
    run--;
    console.log("While Loop");
}

var testFunction = function() {
    do {
        console.log("Do test");
        var j = 1;
    } while (j < 3) {
        j++;
        console.log("Do/While test");
    }
};

test();

#2

This is all invalid code and should be removed.

 {
        j++;
        console.log("Do/While test");
    }

Then modify the expression in the loop to change the value of j (don't declare it in the loop)

    var j = 1
    do {
        console.log("Do test");
        j++;
    } while (j < 6);

Note the syntax differences between this loop and the while above it.