From: Judson Lester Date: 2008-01-12T06:33:53+09:00 Subject: Re: Loop question On Jan 11, 2008 12:33 PM, Mark Mr wrote: > I'm trying to figure out an easier way to work with loops in ruby. > Basically this is what i have now > > @this_question.answers.each do |a| > missing_flag = true > if (a.answer == row[cell]) > reply.reply = a.id > missing_flag = false > end > if (missing_flag) > puts "Not Found" > end > end > > Is there any way to avoid using this flag method? I want to put a > condition on the .each statement that says if no a.answers = row[cell] > then dont do the reply.reply = a.id. I cant do an else because it would > run the else after every element in the answers, and i only want it to > be done after all of them have been run. BTW i'm kind of new to ruby. > Any suggestions? thanks :) > -- > Posted via http://www.ruby-forum.com/. There are a couple of flow control tools you could use. You could raise an exception, for instance, or return the value from a method, and then puts "Not Found" if you complete the loop. Just because it's lesser known, though, I'll point out: catch :found do @this_question.answers.each do |a| if (a.answer == row[cell]) reply.reply = a.id throw :found end end puts "Not Found" end Judson -- Your subnet is currently 169.254.0.0/16. You are likely to be eaten by a grue.