8/8 For Loop do not print 0


#1

I have the for loop starting at 100 counting down to 0 but not sure how to not print 0? would I have to inclue an if statement?

for (var i=100;i>=0;i-=5){
console.log(i);
}


#2

simple:

for (var i=100;i>0;i-=5){
    console.log(i);
}

let me explain, when you use i>=0 when i is 0, the loop will execute (condition is true) and print 0, when use i>0 the loop will not execute when i is 0 because the condition is false. this way you prevent zero from being printed


#3

simple indeed, makes pefect sense. Made modification as follows and I am now not printing 0. Thanks!

for (var i=100 ;i>0;i-=5){
console.log(i);
}


#4

for (var i=100; i >= 1; i-=5) {
console.log(i);
}

This is the coding that helped me move forward to the next step.
When I had i >=0 // it did not allow me to move forward
When I had i>=5 // I was not completing the 100 - 5 loop required

Thus, i >=1; // hope this helps somebody else!