11. Review / infinite loop again! (Must be a radical misconcept...)


#1


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


Hello, it's really a shame, but I get infinite loop for this kind of do/while loop. (Only the 3rd program certainly.) What is wrong with my understanding? I'm suspicious of the curly brackets and/or semi-colons.


var i=0
for (i; i<18; i+=2)
    {
    console.log(i);
    }
    
var i=0
while (i<20)
    {
    console.log(i++);
    }

var lookForEven = function(n)
{
do
    {console.log("Your number is odd.");}
while (n % 2 === 0);
}
lookForEven(6);


#2

As long as you input a number that leaves no remainder, the loop will execute forever. I input 7 and the text logged once to the console.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.