12. Why is this an infinite loop?


#1

var names =[ "Rahul", "Sam", "Anjali", "Shilu", "Sonam"];
for ( var i = 0; i < names.length; i = i++);
{
console.log("I know someone called" + names[i]);
}

what is the problem in the below code, when i submit this code page become unresponsive every time


12. Loops and Arrays II (Why does this work?)
#2

i = i++ is wrong

try just i++

Also I have been stuck on this lesson for 13 mins, only to find that my code is fine but i used a "i' not a "I" in the "I know someone called ".......


#3

I changed the code

var names = [ "Rahul", "Sam", "Anjali", "Shilu", "Sonam"];
for ( var i = 0; i < names.length; i++);
{
console.log( "I know someone called" + names[i]);
};

but still not fixed.
Now it says - Make sure to type the 'I know someone called ' part exactly right


#4

after called, there should be a space


#5

I done the same but still same problem

var names = [ "Rahul", "Sam", "Anjali", "Shilu", "Sonam"];
for ( var i = 0; i < names.length; i++);
{
console.log( "I know someone called " + names[i]);
};


#6

your for loop:

for ( var i = 0; i < names.length;  i++);

what is the semi-colon doing at the very end?


#7

That ends the coding

Okay I removed that but one more problem

I know someone called 0Rahul
I know someone called 0Sam
I know someone called 0Anjali
I know someone called 0Shilu
I know someone called 0Sonam

why is 0 before every name?


#8

yes, it does. but it shouldn't, because the {} are still part of the for loop


#9

I have fixed that , thank you