I think you will need to check the exit condition in a separate thread:
# check for exit condition Thread.new do loop do exit if gets.chomp == 'q' end end a = 0 loop do a += 1 puts a sleep 1 end
BTW, you will need to enter q<Enter> to exit, as standard data entry does.
Mladen jablanović
source share