While Loops!


#1

OK, I just want to be sure that i'm understanding this right. so..

1.We start of declaring Count = 0 : to say that what we are printing will start at 0 and not that the statement is false? is that correct?

2.and we write loop(); at the end of the statement to run our while function right? That is too make it come to life/action?
Thank you very much in advance...

This is my code:
var count = 0

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

loop();


#2

1 Yes we start with count having a value of 0. I'm not sure what you mean by printing. It just has a value of 0 so console.log(count) would print 0. 0 also has the side effect that it has a value of false so 0 == false would be true but we're not using this here right now so don't bother about it.

(1b) The condition we use is count < 3 so as we start with count = 0 this means 0 < 3 which is true. As we increase count with every loop it will after 3 loops have a value of 3 and then the condition is 3 < 3 which is false and the loop stops.

2 You're basically correct about the second one just want to emphasize that you're not calling the "while function" because it is a while loop but the function that is named loop. As the only thing inside the function is this loop calling the function means starting the loop just wanted to make sure that it is clear what you call.

I hope that was not too confusing :slightly_smiling: