From: Matt Armstrong Date: 2003-01-28T16:31:04+09:00 Subject: Re: loop while Tim Bates writes: > Why can't I do: > > loop while t.gets !~ /[Cc]onnected/ If you want a one liner: while t.gets !~ /[Cc]onnected/; end or until t.gets =~ /[Cc]onnected/; end or loop { break if t.gets =~ /[Cc]onnected/ } Note that all of these will fall into an infinite loop at end of file since both "nil =~ Regexp" and "Regexp =~ nil" are always false. > Is there a similarly terse but readable way of doing this? I just want to > throw away all input until I reach the 'connected' line (assuming t is a > TCPSocket...) I would probably end up with: while line = t.gets break if line =~ /[Cc]onnected/ end fail "EOF waiting for Connected line" unless line because I value robustness over terseness. ;-)