When to "while" and when to "for"


#1

I can't print the result for the 'while' loop but my 'for' loop works fine.

var a = 0;
while(a){
console.log("Go fish yourself");
a = 1
};

for(var i = 0; i < 10; i++){
console.log("Go for yourself");
};


#2

while(a){ <--- // This Line

a = 1; <--- // This Line

let's translate what the console sees to English.


while "a", a is equal to 1.

That doesn't make sense to me, I don't know about you. What would sound better is something like this:

"while a is less than 10. a will increment by 1 and print 'Go Fish yourself'". See if you can't find a way to translate that to code.


#3

As @lolmain already mentioned you're using a value instead of a condition. This works but is not explicitly covered in this track. If you google it you'll find:
http://www.sitepoint.com/javascript-truthy-falsy/
that 1 has a value of true and 0 has a value of false. So as you start with 0 you're loop will never start. On the other hand if you would start it the a = 1 would turn it in an infinite loop. So better use real conditions which might even be more obvious to understand.


#4