Tim Pease wrote:
> 
> You will need to run your loopy method in a separate thread, and then
> kill that thread when the user presses any key on the keyboard ...
> 
> t = Thread.new do
>    i = 0
>    while true
>      i += 1
>      puts i
>    end
> end
> 
> gets
> t.kill
> 
> The above code won't work with any keypress -- you have to hit enter
> in order to stop the program.
> 
> Blessings,
> TwP


That does work properly.

Is starts to display

1
2
3
...
...
127

then stops and I presume is waiting for the "gets"

To put this into some context;

I have a socket client program that continously reads data from a 
server, the only way I have currently to stop it is to do a CTRL-C, I 
want/would expect a more elegant way of performing an exit on a loop.

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