From: 7stud -- Date: 2007-10-14T11:08:31+09:00 Subject: Re: Can you terminate an each_line statement. Jayson Williams wrote: > Is there a way to terminate an each_line iteration before it iterates > through every line? For instance: > > file = open(url) > > file.each_line{|line| > found = true if if line.include?('string') > break if found == true > } > > Is it possible to to break out of the each_line statement if found is > true? File.open("data.txt", "w") do |file| (1..5).each do |i| file.puts("line #{i}") end end File.open("data.txt") do |file| file.each_line do |line| puts line break end end --output:-- line 1 -- Posted via http://www.ruby-forum.com/.