Forum: Ruby Re: increasing counter whithin loop?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
87e9a89c53ccf984db792113471c2171?d=identicon&s=25 simon.kroeger.ext (Guest)
on 2005-12-05 15:18
(Received via mailing list)
perhaps:

a.inject(false) do |skip, elt|
  puts elt if !skip
  elt=="b"
end

(no, I don't think this is realy nice)

cheers

Simon
18ca239ffade6df0b839d26062f173fb?d=identicon&s=25 dbatml (Guest)
on 2005-12-06 04:25
(Received via mailing list)
On Mon, 05 Dec 2005 15:13:46 +0100, Kroeger, Simon (ext)
<simon.kroeger.ext@siemens.com> wrote:

> (no, I don't think this is realy nice)

Here is another (not really nice) way to do it, using the flip-flop
operator:

>> %w( a b c d b e ).each { |el| nil if (puts(el) || el == "b")...true }
a
b
d
b

Dominik
This topic is locked and can not be replied to.