Error!

#i m just beginner

num=18
loop do
next if num%2==0
puts num
num-=1
break if num<=0
end

#i want to print numbers from 18 to 0 but only even numbers
what am i doing wrong??

That line is rejecting even numbers. Change == to != and try again.

its still showing error @mtf );

instead of printing all the even numbers from 18 to 0 , its only printing 18

Link to exercise, please. Thanks.

Did you try print instead of puts?

So where is that link, then?

thanks for your help @mtf but it not working.
there is no link for that, i m trying it by myself

What would we call this, then…

Next!

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

yeah yeah…sry
that was the question

Please make a point of starting every new topic with a link to the exercise. It makes it so much simpler to get right to the bottom of things.

1 Like

okay…can u please tell me where i did the mistake in my code??

Please re-post what you have now. Thanks.

num=18
loop do
  next if num%2!=0
  print num
  num-=1
  break if num<=0
end

Does your code output look like this…

181614121086420

?

sadly no, just 18

thats why i m confused, exhausted too );

Can’t for the life of me figure why your code runs into an infinite loop. This works and passes,

i = 20
loop do
  i -= 1
  next if i % 2 != 0
  print i
  break if i <= 0
end

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