Why following code is producing infinite loop?


#1

Why is following code producing infinite loop? isnt this supposed to work normal?

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

but following code is OK.

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


#2

Try executing it in your head


#3

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