For or While


#1

So I have this

for (var i = 1; 1 <101; i++) {
console.log(i);
}

but I keep getting an infinite loop and it crashes my browser, I never really got the hang of loops because in every question with them I always got infinite loops :confused:


#2

change 1<101 to i<101 and it should work :smile:


#3

Loops run when their condition is true and your is independent of variables and always true: 1 is less then 101 and always will be. As @tomkur2 already implies you could fix this by using i instead of 1.
Also if you have trouble with loops maybe this is overview is helpful for you: