Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Problem with "retry" statement in Ruby Foundations > Loops > Control Flow Course

I've been trying to do Jason's Control Flow exercises in Ruby Foundations; one issue I'm having is with the retry example:

animals = %w(dog cat horse goat snake frog)
count = 0

for animal in animals
  puts "The current animal is #{animal}"
  break if count == 10
  count += 1
  retry if animal == 'horse'
end

When trying to run this, I receive this error:

V:\Source\loops>ruby loops-11.rb
loops-11.rb:15: Invalid retry
loops-11.rb: compile error (SyntaxError)

This is my version of Ruby:

V:\Source\loops>ruby -v
ruby 1.9.3p286 (2012-10-12) [i386-mingw32]

After doing some googling, I found that retry is no longer supported outside of a rescue block in Ruby 1.9. However, Jason's prompt shows he is using version 1.9.3. Is there something I'm doing wrong, a missing gem, anything? Does anyone know of a way that's supported in Ruby 1.9 that will produce the output Jason has in his lesson?

Thanks,

Leo

6 Answers

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hey Leo,

I just notified Jason about this. He should be able to help you soon. :)

Thanks Nick, I appreciate it.

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hi Leo,

We have this on the list of things to address. There was a bizarre ruby conflict on the machine when I was recording that screencast and 1.8.7 had priority even though 1.9.3 was shown in the terminal. Don't worry, you're correct about the retry statement and Ruby version. Thanks!

Hey Jason,

I blame pik, even though you probably use rvm. I've just spent half a day trying to get it running smoothly in Windows 8.

Thanks a lot for the courses, I feel like I have a foundation to grow on with respect to Ruby. Now on to the PickAxe!

Has a solution to do the same functionality been found?

Hey guys, running ruby 2.0.0p451 now and still having this issue. Is retry not allowed outside the rescue block anymore? Any place to look for help on the extra credit problem for this section if so?