I am learning javascript and I have two questions hope you can help :)
I have two for loops iterating backwards
- first example :
for (var i = 10; i--;) {
console.log(i, "backward");
}
// starts at 9 and stops at 0
// without breaking condition
- second example :
for (var i = 10; i >= 0; i--) {
console.log(i, "backward");
}
// starts at 10 and stops at 0
// with breaking condition that i >= 0
- why in the first example we don't need to set a breaking point for the loop ? like
i > 0? is it because 0 is false anyway ? so when it reaches 0 it automatically breaks ? and it won't keep iterating like 0, -1, -2, -3, ....etc ? - why in the second example the iterating starts at 10 while in the first example it starts at 9 ?
thanks for your support :D Cheers
optionaland explains what happens if they're omitted.