Break from a block

Hi,

How to break a block with such the method like each?
for example:

File.new("big.txt").each do |s|
    if s =~ /abcd/
       puts s
       break  # is this right?
    end
end

Thanks!

Hi,

How to break a block with such the method like each?
for example:

File.new("big.txt").each do |s|
  if s =~ /abcd/
    puts s

    break # is this right?

  end
end

Thanks!

Yes. Does it not work when you run it?

···

2010/11/24 Eva <eva54321@sina.com>

Yes that's right - minus all the &nbsp;'s :slight_smile:

irb makes it very easy to experiment with the language.

irb(main):001:0> (1..10).each { |x| break if x > 4; puts x }
1
2
3
4
=> nil

···

--
Posted via http://www.ruby-forum.com/.