From: Robert Klemme Date: 2009-07-07T21:02:13+09:00 Subject: Re: Breaking the loop in case of EOF 2009/7/7 Brian Candler : > Marcin Górski wrote: >> I need to break a loop when program gets an EOF from STDIN. > > gets will return nil in this case. > > while str = STDIN.gets >  str.chomp! >  puts "String: #{str}" > end > > Beware that "STDIN.gets" is subtly different from a bare "gets". The > first always reads from STDIN. The second will read from the files named > on the command line if the command line is not empty. (See also ARGF). I believe a more idiomatic way would be STDIN.each do |str| str.chomp! puts "String: #{str}" end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/