Next in Loop section lesson 11


#1

Can not figure out how to showcase odd value.

This is what I got and it's not working.

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

this is my error : It looks like your loop doesn't print out the numbers 18 to 0.

and this is my result in the console :
19181716151413121110987654321-2nil

obviously my odd numbers still printing.


#2

You want to pass to the next iteration IF the number is NOT even. next if !(i % 2 == 0)


#3

that is awesome! than you. so simple yet hard to think of the simplest solution.


#4

It will get easier as you work in programming. :slight_smile:


#5

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