How to loop this three times


var android = 0

var loop = function(android){
	    android = false;
		console.log("I'm looping!");



Replace this line with your code. 


Hey @mtap52190,

You should instead use a variable, and iterate over it while it is less than a certain value...


Well, this is how I loop that 3 times. If you think it's good, you should try:
var loop = function(count) {
while(count<3) {
console.log("I'm looping!");


why do we add that last zero in between the loop brackets?


I believe that he added that there by accident, so just ignore it. He was just calling the loop function and must have accidentally hit 0 or something of the sort.


Actually the 0 in the parenthesis of loop is a good idea, so hopefully it was not done by accident.
Maybe review the part about functions and parameters.

What happens is that the argument (the value in the parenthesis: here 0) gets assigned to the parameter (the value in the parenthesis after the function keyword: here count) so here the loop starts from 0 due to the 0 in the function call. That actually makes a lot of sense, because unfortunately a lot of folks build functions that can only run once, while this could work as often as you need it.


Oh wow, I didn't know that you could do it that way; I learn something new every day don't I :slight_smile:


yeah I played around with it and figured out what was going on but if I already put count in the brackets in between the function, shouldn't that work by itself since I've already declared initially set count to 0 and increasing it by 1. I tried the loop without adding 0 at the bottom but it didn't work.


I just declared count as a variable, made the loop, and then called the loop.

And I just realized what @haxor789 was pointing at, I had just gone brain dead :slight_smile:


by adding it in the parenthesis after function you declared it right. Now it has a value of undefined and using ++ on count means undefined+1 which is NaN. You might be able to leave the loop with this but it is probably not what you intended to do, do you?

Also could you post the code your talking about?


Actually, I'm a girl. Please don't call me "he". And I'm from Vietnam. So glad to have some one who is also interested in coding. :slight_smile:


hey it's cool. I realized typed it in again and it worked. Must've done something wrong the first time. Thanks a lot for the help though.


Thanks a lot, I didn't know I could use count++ solo like that. I thought it had to be inside the parenthesis like in all the other examples. I need to start thinking outside the box.


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