Error!


#1

#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??


#2

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


#3

its still showing error @mtf );

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


#4

Link to exercise, please. Thanks.

Did you try print instead of puts?


#6

So where is that link, then?


#7

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


#8

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

#9

yeah yeah…sry
that was the question


#10

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.


#11

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


#12

Please re-post what you have now. Thanks.


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

#14

Does your code output look like this…

181614121086420

?


#15

sadly no, just 18

thats why i m confused, exhausted too );


#16

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

#17

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