From: Austin Ziegler Date: 2003-08-13T01:19:38+09:00 Subject: Re: Elegant solution for a loop-break problem On Fri, 8 Aug 2003 00:00:15 +0900, KONTRA Gergely wrote: >>> Is there something similar to python's for .. else ... structure? (Do >>> something, ONLY when the loop is terminated normally (without break) > for element in array > if element==value > puts "#{element} found in array!" > break > end > else > puts "#{element} not found in array" > end This could be done with: if array.find { |e| e == element } puts "#{element} found in array!" else puts "#{element} not found in array!" end Alternatively: if array.include?(element) puts "#{element} found in array!" else puts "#{element} not found in array!" end It may not represent your full case, but I find that using the built-in iterators generally does more than a for loop in other languages and that there's some iterator that will do what is needed. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.08.12 * 12.14.03