Next!


#1


https://www.codecademy.com/courses/ruby-beginner-en-XYcN1/2/2?curriculum_id=5059f8619189a5000201fbcb

Console: 1817161514131211109876543210nil

error: Oops, try again. It looks like your loop doesn't print out the numbers 18 to 0.


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


#2

Instruction:

Use the next keyword so that you skip to the next iteration if the number i is odd.

so in your code here

next if i - 18 == 1

what does it mean? it'll just not print 19 .but the instruction is something else.

if the i is odd then it'll go to the next.

you just have to think how can you check whether i is odd or not


#3

yes! thanks :smiley:

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

Byebye
#4

Interesting, I was able to get using this:

next if i % 2 != 0

Yours makes more sense though lol!


#5

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