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
Austin Bebber
7,044 PointsControl Flow video "Retry command"
Hi,
I love your videos and enjoy finding out how to repeat the exercises using Window's version, cmd. During the Control Flow video at '4:30' he uses a function in the line :
retry if animal == 'horse'
My cmd output was
forloop.rb:8: Invalid Entry forloop.rb: compile error (Syntax Error)
I continued on through the exercise and the next example was to change it to:
redo if animal == 'horse'
And the above example worked.. Is their a different name to call certain function in cmd versus apple's system? Retry doesn't seem to work but Redo does.. anyone else experience this?
Austin Bebber
7,044 PointsI also took a screenshot of my desktop showing a comparison versus the video if I could attach it or send it to someone. What makes it so weird is when I change 'retry' to 'redo' on line 8 it works, which is the next example on the video.
animals = %w(dog cat horse goat snake frog)
count = 0
for animal in animals
puts "The animal on the screen is #{animal}"
break if count == 10
count += 1
retry if animal == 'horse'
end
And here is the cmd output.
hopeso.rb:8 Invalid Entry
hopeso.rb: compile error (Syntax Error)
John Paul Ashenfelter
1,118 PointsAh! I bet you're running Ruby 1.8.x on one machine and Ruby 1.9 on another (you can check with ruby -v)
Austin Bebber
7,044 PointsI have just one computer and it's Ruby 1.9.3 but thank you for your answer. I figured something must have been out of my control since the next example worked.
I seem to have another issue I can't solve with the treebook sign up page. I'm redoing the exercise but if I can't solve it, can I post another question to you or should I start another message?
1 Answer
John Paul Ashenfelter
1,118 PointsThe retry command was changed in Ruby 1.9 and above to work quite differently -- generally as a rescue in a begin/end block. So this example only works in Ruby 1.8.x
John Paul Ashenfelter
1,118 PointsJohn Paul Ashenfelter
1,118 PointsIt would be great to see the code for forloop.rb -- the ruby compiler is telling you there's an error in your code.
There should be no difference between Windows and OSX when running the same ruby commands