Lesson 9 use of next

#1

Lesson is quite clear to print on the console either odd or even numbers by using Next i % 2 == for skipping even nos and use Next i % 2 != for skipping odd nos between i no .. no but it is giving following remark which is not understandable.Pl explain
Oops, try again. It looks like your loop doesn't print out the numbers 18 to 0.

#2

The code should skip if the number is odd. An odd number is an integer which is not a multiple of two. To find out all the integer which are not a multiple of two we can use modulo. If the remainder is 1 the number is an odd number as the remainder otherwise would be 0. The code needs to look like this:

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

#4

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

#5

because you have a mistakes in your code.
right code:
i = 20
loop do
i -= 1
next if i % 2 == 1
print "#{i}" #<== if you will use right syntax's you will be ok. I've had same issues. Just be careful when you wright your code
break if i <= 0
end

#6

thanks, i already found the way)

#7

Thanks, I was stuck on this for hours for the fact of not recognizing the integer swap and maybe beer.

#8

i would like to know that way brother

#9

sry, i forgot a bit what about i thought at that time). May you ask me what the problem you really have?

#10

lol...that was my issue too (beer)!

#11

@beer I thought I was the only one