Search code examples
rubyloopsinfinite-loop

Creating an infinite loop


I'm trying to create an infinite loop, where a block of code will be executed forever.

All loop documentation I have found warns against creating an infinite loop, but no examples of a working one.

If I have a block of code:

{ puts "foo"  
  puts "bar"  
  sleep 300 }

How would I go about running this block forever?


Solution

  • loop do
      puts 'foo'  
      puts 'bar'  
      sleep 300
    end