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.
simon.kroeger.ext (Guest)
on 2005-12-05 16: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
dbatml (Guest)
on 2005-12-06 05:25
(Received via mailing list)
On Mon, 05 Dec 2005 15:13:46 +0100, Kroeger, Simon (ext)
<removed_email_address@domain.invalid> 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.