Reason #152 • June 1st, 2026

Until loops

Pretty much all programming languages have a while loop, which executes a block of code repeatedly as long as a given condition is true, and so does Ruby.

Now, if you were already annoyed with Ruby's unless conditional, I have bad news for you, because in a similar spirit, Ruby also provides us with an until loop, which executes a block of code repeatedly while a given condition is false:

Ruby
queue = Queue.new

queue << "job 1"
queue << "job 2"

until queue.empty?
  job = queue.pop
  puts "Processing #{job}"
end
# Output:
# Processing job 1
# Processing job 2
    

While it's rare to use either while or until loops in Ruby, given the prevalence of iterators and enumerables, they still have their use cases, and when they do come up, I'm sure glad I don't have to write while !queue.empty? to get the job done 😇

History

until has been around since Ruby's inception.

The first programming language I'm aware of with an until loop was Pascal with its repeat ... until.

The most likely inspiration for Ruby, however, was Perl's until loop, which behaves very similarly to Ruby's.