They want me to loop 18 to 0 but i can only do it the other way around, need help


#1

for i in 0..18
i += 1
next if i % 2 == 0
print "#{i}"
end


#2

I don't think there's any exercise asking for 18 to 0. There's an exercise asking 20 to 0 however, but it's asking to use loop...do, not for...in.

Also, the for loop can't use a decreasing range (you're not supposed to use for anyway, but just to let you know).

Try to modify your code with a loop...do, and tell me how it works out.


#3

when i submit my answer it sends an error saying, "your loop dose not show 18 to 0"


#4

Please give me the number of the exercise you're on.


#5

Loops & Iterators
Iterators & Blocks
.9 Next


#6

Okay, you're supposed to just modify the loop you used to pass the previous exercise, which is a loop...do, not a for...in .


#7

still says "It looks like your loop doesn't print out the numbers 18 to 0." But thanks for pointing that out.
i = 20
loop do
i -= 1
next if i % 2 == 0.5
print "#{i}"
break if i <= 0
end


#8
next if i % 2 == 0.5

A modulo operation will always give an integer.


#9

Like suggested above, your line next if i % 2 == 0.5 needs some work.

Keep in mind you can tell it to skip if it doesn't equal a value for example %2 != 0

Hope that helps:)


#10

Thank you arjofococolovi and mark_hollingsworth i tried it again after school and figured out the way that mark just mentioned when i looked on the forms after, just needed to clear my head a bit i guess Thank you again :relieved: