Unknown infinite loop



My code keeps making an infinite loop.

i = 20
loop do
     next i % 3 == 0
   i -= 1
   print "#{i}"
   break if 1 <= 0


there should be an 'if' after your next


I tried that, but then it creates an infinite loop.


i = 20
loop do
i -= 1
next if i % 3 == 0
print "#{i}"
break if i <= 0

If you refactor your code to do this(move your increment before your next statement), it will output =>19171614131110875421

However this isn't what the lesson calls for. It wants even numbers printed

Try next if i % 2 == 0


Thank you! I'll try that next time.


Add a line to your loop before your print statement. Use the next keyword so that you skip to the next iteration if the number i is odd.

That means using 2 to test parity.

break if i < 1

will work nicely, as well.


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