Lesson 9 in ruby for loops and iterators is confusing help



(ruby):7: syntax error, unexpected $end, expecting keyword_end

i = 20

loop do
for i in 1..20
  next if i -= 2 == 0
  print i
  break if i <= 0


You are supposed to only use loop do. Mixing two loops together (loop do and for i in) is bad.

In the next statement, your condition has to check if i is odd (how do you check if a number is odd? :wink:)

You also have to keep subtracting 1 from i each iteration so that the break conditition can be met and the loop hence exited (so that the loop does not become an infinite loop).


thanks, I'm sorry \i didn't see this sooner :slight_smile:


I'm not sure why this isn't working. Can you give me any hints?

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

Thanks in advanced.


First of all
you are using the modulo-operator


I understand now. I had the wrong remainder for odd numbers divided by 2. Thanks!