From: Nikodemus Siivola Date: 2002-07-09T20:13:45+09:00 Subject: Re: for ... else ... end On Tue, 9 Jul 2002, Yukihiro Matsumoto wrote: > But I don't feel "for .. else" is intuitive. The "else" seem like > indentation mistake rather than loop termination hook. Maybe there > can be a more suitable keyword. Why not : "iterator ... then ... else ... end" while cond { # stuff } then { # more stuff after succ. iteration } else { # handle failed iteration } collection.each do |item| # handle item then |collection| # handle collection after succ. iteration else |collection| # handle collection after failed iteration end But then again, I get the feeling that instead of extending syntax for this specific case there should be a way of defining your own control structures by chaining blocks: (I believe SmallTalk has something like this?) def iter &all then &ok else &err ok = true for x in @array yield(x) &all || { yield(self) &err; ok = false; break } end yield(self) &ok if ok end collection.iter { |x| break unless x.test } then { |all| all.stamp } else { |all| all.dump } -- Nikodemus