user3476791
user3476791

Reputation: 1092

retry in Ruby can not be performed

for i in 1..5
   retry if  i > 2
   puts "Value of local variable is #{i}"
end

When I ran the code above, I got an error message saying Invalid retry

The version of Ruby I was using is 1.9.3. Would anyone know what went wrong with the code?

Upvotes: 2

Views: 347

Answers (1)

jamesc
jamesc

Reputation: 12837

From Ruby 1.9 onwards retry needs to be in a rescue clause and will only work when in a rescue clause

Upvotes: 3

Related Questions