Catch 22 Error in Loops & Iterators: Next!


#1

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

I'm stuck in the first Loop lesson. If I use the next command, the lesson will want me to put in all numbers from 18 to 0, and if I don't use it, the lesson asks me to use the next command to get rid of odd numbers

#Error: "The loop doesn't put the numbers 0 through 18
num = 19
   loop do
   num-=1
        next if num % 2 != 0
   puts num
break if num < 1
end
# error: Make sure to use the 'next' keyword to skip over the odd numbers in
num = 19
   loop do
   num-=1
   puts num
break if num < 1
end

Have any of you had similar problems, and if so, were you able to resolve them?


#3

What output is being printed to the screen? Is it all on one line with no whitespace? Are you printing 0 (it too is even)?


#4

It will either print a string from 0 to 18, or it will print all of the even numbers. I go from zero because that is the way that most counters operate on computers, and I will receive the same error "It looks like your loop doesn't print out the numbers 18 to 0". I believe this is merely a bug, and I will have to report it if I can't solve this bizarre error loop.


#5

Not a bug. A clue. Satisfy this condition in a single expression with no whitespace.

181614121086420

#6

Huh, looks like my code had the bug! It looks like it somehow didn't put in a 0 at the end. Whoops! Thanks for the help!


#7

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