Never Escape This Ruby Loop. Also, Here's How.

ruby dev.to

This is a self-translation of an article I originally wrote in Japanese. Hello. I'm Pocke. In this article I'll show you how to define a loop in Ruby that you can never escape from. A loop you can escape Ruby has the Kernel.#loop method. It's a method that evaluates its block over and over, forever. # "hello" is printed forever loop do puts "hello" end Naturally, you can also break out of loop. # Prints "hello" once, then leaves the loop loop do puts 'hello' break

Read Full Tutorial open_in_new
arrow_back Back to Tutorials