When to 'While' and when to 'For'


#1

Someone pls help me! I am stuck on an infinite loop and I don't know how to change my code!

var count = 12

while (count => 0) {
    count++
};
    
    
for (var i = 0; i < 50; i++) {
    console.log(i);
}

#2

Because your condition i while loop is 12 > 0. Inside the loop you have count++, so now count = 13 (and it also > 0).
So you need to change your condition.

while - loops through a block of code while a specified condition is true


#3

Thanks for the advice.
I solved it. :grinning:


#4

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