Ruby: 'Until' loop keeps repeating


#1



The 'Until' loop in Ruby has me hung up. I'm not too sure why it keeps going into an infinite loop.


When I attempt to change things around I sometimes get a "The program took too long to finish. Check your code for infinite loops and try again." message but other than that it just goes into an infinite loop. Below are a two of my attempts. Thanks in advance!


# My attempt 1 - 
counter = 1
until counter == 10
    puts counter
  counter += 2
end

# My attempt 2 - 
counter = 1
until counter == 10
  counter += 2
end
puts counter

# Code academy's example
i = 0
until i == 6
  i += 1
end
puts i


#2

Your counter will never equal ten in your code
It starts at one and gets incremented by two.
1,3,5,7,9,11,13,15 and so on
Because it is never equal to ten....it never breaks.

Try a different comparator


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.