8. When to 'while' and when to 'for' - Why does it keep crashing?


#1


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


My code crashes every time I click Save & Submit.


 var it = true;
var is = function() {
while(it) {
console.log('no');
it = false;
}
};

var not = function() {
for (var p = 1; 1 < 11; p++) {
   console.log(p); 
}
};

not();
is();


#2

here:

for (var p = 1; 1 < 11; p++)

1 will always be less then 11, so its an infinity loop


#3

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