From: Jari Williamsson Date: 2008-01-30T21:05:42+09:00 Subject: Re: For Loop question Dick Davies wrote: > question_array.each { |element| > next if element.nil > element.do_something > } > > will call do_something() on every element in the array that isn't nil. Or a version that will break after the first non-nil: question_array.each { |element| next if element.nil break element.do_something } > If you just want to do something with the first non-nil element, you could do > > non_nil = element.find { |e| !e.nil? } > non_nil.do_something To protect from arrays with all-nils: non_nil = element.find { |e| !e.nil? } non_nil.do_something if non_nil Best regards, Jari Williamsson