From: Robert Klemme Date: 2008-01-12T07:29:57+09:00 Subject: Re: Loop question On 11.01.2008 21:33, 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 Are you sure you have the flag evaluation in the right position? It seems you want to be looking through @this_question.answers to find the matching entry, don't you? > 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 :) ans = @this_question.answers.find {|a| a.answer == row[cell]} if ans reply.reply = ans.id else puts "nada" end Cheers robert