From: Gregory Millam Date: 2004-05-31T19:01:43+09:00 Subject: Re: elegant way to say "try this thing, one at a time, until condition is met" Received: Mon, 31 May 2004 17:31:24 +0900 And lo, David wrote: > Example: I need to unmount /usr and /usr2, but currently I can't because > there are some opened files from those partitions. I am going to try > shutting down daemons or killing some processes (or other things), one > at a time, until I can unmount it. > ... > But still it's not pretty enough. Any more elegant way? > Use a flow control that allows arbitrary exits. Such as returns and breaks def cond_met? umount("/usr") && umount("/usr2") end if it's a function: def myfun system '/etc/init.d/httpd stop' system '/etc/init.d/squid stop' return if cond_met? system 'killall -INT motherinlaws' return if cond_met? ... etc end else: loop do system '/etc/init.d/httpd stop' break if cond_met? system '/etc/init.d/squid stop' break if cond_met? system 'kill -9 pig ; /bin/fry pig' break if cond_met? break # This is needed so it doesn't actually loop :D end - Greg