Next statement in Loop


#1


https://www.codecademy.com/en/courses/ruby-beginner-en-XYcN1/2/2?curriculum_id=5059f8619189a5000201fbcb

This code generate error message
"Oops, try again. It looks like your loop doesn't print out the numbers 18 to 0."
How to fix it?

i = 18
loop do
    i -= 1
    next if i % 2 == 1
    puts i
    break if i <= 2
end


#2

Is the error message correct? What does your code print out instead?


#3


#4

You can see from your output that you are not printing 18.

Have a look at your code, follow your i variable through each line.

The first time through your loop, what is the value of i after line 3?


#5


#6

now i change code and it prints 18 to 0, but error still occur


#7

Here are instructions regarding program or task.


#8

Your code is correct, but instead of puts you have to use print.

It's usually bad idea to change the base code if you are not asked to do so.


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.