Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Loops Ruby Loops The Ruby Loop

Loop construct

Plese help because with these code because I haven't found the error.

loop number numbers = [] number = 0 numbers["number"] number += 1 break if number = 3 end end

Thanks for your help.

loop.rb
loop number
numbers = []
number = 0
numbers["number"]
number += 1
break if number = 3
end
end
Kirill Lofichenko
Kirill Lofichenko
10,761 Points

You are missing the word "do" after loop. The correct use of loop construct would look like this: loop do end

2 Answers

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

There are a couple of issues. You are not adding to the array. There are a few methods to insert a number into an array. You can use the push method or a double less than sign which is synonymous. When you try to set the condition you are using an assignment instead of a comparison operator. You have two end and no do keyword. You are not checking the length of the array but instead assigning three to the variable ...

Here is an example of what your code could look like:

numbers = []
number = 0

# write your loop here
loop do
  numbers << number
  number += 1
  break if numbers.length == 3
end

Thanks a lot!