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

ruby loops Challenge Task 1 of 1

I am not sure how to write the code

loop.rb
numbers = [0]

number = 0

# write your loop here
loop do
  add number = [1]
  if number == "0, 1, 2"
    break
  end
end

2 Answers

Sage Elliott
Sage Elliott
30,003 Points

Hello, Sara! You're on the right track but your code needs a few changes to pass!

numbers = []

number = 0

# write your loop here
loop do
  numbers.push(number)
  number += 1

  if numbers.length >= 3
    break
  end
end

The numbers.push(number) adds the value of "number" into the numbers array, the "number += 1" adds 1 to the value every time it is looped(first loop = 1, second loop =2, etc.) and the if statement here will "break" when the value is greater or equal to three. I hope that helps!

Thank you!