From: Stephen White Date: 2001-08-23T05:22:24+09:00 Subject: [ruby-talk:20119] Re: The Ruby Way [was: Ruby Article] On 22 Aug 2001 15:23:01 +0900, Ryo Furue wrote: > > > II) Use catch/throw for control structures, use rescue/raise for > > > communicating errors. > [...] > > > catch (:done) do > > > loop do > > > # Note: prompt_and_read can throw :done > > > first_name = prompt_and_read "First name" > > > last_name = prompt_and_read "Last name" > > > phone = prompt_and_read "Phone" > > > > > > myfile.puts first_name + "\t" + last_name + "\t" + phone > > > end > > > end Next iteration through this little loop... :) File.open('phonespec.txt', 'a') do |myfile| questions = ["First name", "Last name", "Phone"] more = true while (more) answers = [] if questions.find do |prompt| print prompt + ': ' answers << str = gets ? $_.chop : 'END' str == 'END' end then more = false else myfile.puts answers.join("\t") end end end No more throw/catch, and a cute way of chopping input. I tried to use a Range in the while() condition, but it seems to re-run the whole Range rather than keeping track as if it were in an 'if'. It seemed like a bug to me but I'm not sure. I'm using 1.6.2 so it's probably already been fixed if it were a bug.