Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Loops Ruby Loops The Ruby Loop

Juan Ordaz
Juan Ordaz
12,012 Points

need help

How can I solve this problem?

loop.rb
numbers = []

number = 0

loop do

    break
  end
end

2 Answers

Hi Juan,

I add comments # that would help you to get ideas, here's something like this, I passed the test.

loop do # create loop construct

    numbers << number  # push number into numbers array
    number + 1  # add 1 to number variable

  if numbers.length >= 3  # if the numbers array has more than 3 items
     break # use the break keyword to exit the loop
  end

end

Hope that helps.

Pablo Quiroz
Pablo Quiroz
7,846 Points
numbers = []
number = 0

loop do
    if number < numbers.length
           puts numbers[number]
    else
           break
  end
end
Juan Ordaz
Juan Ordaz
12,012 Points

You got skills, this example looks very simple. I still have to practice how to a code in different ways. I am working on it. Thank you!!!