Next statement in Loop


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


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



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?



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


Here are instructions regarding program or task.


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.


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