0

I know this is a newbie question, but I need help with iterating backwards. My for loop problem is that I have to iterate backwards by 5 from 100. And I have to console.log all numbers excluding 0. This is what I have.

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

Does anyone have any suggestions how to print out the iteration backwards without 0? Sorry if this is simple, I was having a real hard time with it.

9
  • 2
    So what is the question ? What is not working ? Commented Nov 2, 2015 at 18:41
  • 10
    If it´s excluding 0, it should be i > 0 instead of i >= 0 Commented Nov 2, 2015 at 18:41
  • 1
    Were you truly unable to solve this problem on your own? Commented Nov 2, 2015 at 18:43
  • 1
    One suggestion : open your console and see in the result. Commented Nov 2, 2015 at 18:43
  • 1
    The console is your friend Commented Nov 2, 2015 at 18:50

2 Answers 2

2

That seems straight forward:

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

Let me know if I've missed something you need

Sign up to request clarification or add additional context in comments.

Comments

0

I think you have it, but you do need to remove the "=" from your expression. This is a different variation.

var i; 

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.