What am I doing wrong?


#1


Practice makes perfect


I really don't know what I'm doing wrong here?


//Remember to set your condition outside the loop!
var count = 0
var loop = function(){
    while(count < 3); {
        //Your code goes here!
        console.log("I'm looping!")
    }
};

loop();







Thanks


#2

Watch out for the semicolon after the while loop's condition:

 while(count < 3);

Here is a longer explanation on the topic. (it is about conditions but applies to loops as well.)


#3

After you resolve your loop syntax, there is nothing in your code that is going track the number of times the loop repeats. As it stands, this is an infinite loop.


#4

Well, if i'm not wrong, as long as the condition in parentheses for 'while" is true it will keep looping.
And your count is 0, therefore it is forever "True" since count is not increasing at all and is lesser than 3. So as it stands, your code is literally infinite.

Do you see count++ after the console.log? This increases count by 1 everytime 'while' loops. Thus as it runs, count is being increased and eventually count becomes 3 or more. Hence when count becomes more than 3, the condition for 'while' and will not stop looping so it has an 'end"

var count=0

var loop = function(){
	while(count<3){
		//Your code goes here!
		console.log("I'm looping!")
		count++
	}
};

loop();

#5

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