Is this good practice?


#1



The hint says:
We actually know we need to loop three times, so we could use a for loop, but we'll use while this time.

If we create a variable called count and set it to 0 outside the loop (on line 2), then do count++ each time we console.log() inside the loop, we'll be able to track how many loops we've made. If we set the while condition to be count < 3, that should do the trick!

**I decided to do it this way. Is this bad practice or is there a better way to do this? Note: it works the way I did it. **


//Remember to set your condition outside the loop!


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

loop();


#2

I wouldn't say "bad" but definitely the above is risky, even while it works in this instance. Safer to use a range (an inequality) than a single fixed value.

while (i < 3) {

}

sets a valid range, ( i less than 3 ) within which to continue looping.


#3

I find anything involving NOT to be more difficult to read than equivalent expressions without them

Anyway, something you really should change above the above code is the formatting of it:

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

loop();

Added spaces in a few places and fixed the indentation. Missing semicolon.