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
PRO
Maximiliane Quel
Pro Student 55,484 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!