Loop through an array until empty : empty « Array « Ruby






Loop through an array until empty


def print_each(array)
  array.each { |x| puts x.inspect }
end

hash = { "A" => "a",
         "B" => "b" }
array = hash.to_a

until array.empty?
  item, quantity = array.pop
  puts "#{quantity} #{item}"
end

 








Related examples in the same category

1.Check for an Empty Array