Can i use two loops in same method?


#1

def countdown(num)
var = true
print "Time to countdown\n"
loop do
num = num.to_i
num = num - 2
puts num
if num.to_i <= 20
num = num - 1
puts num
break
break if num == 0
end
end
end

countdown(40)

Forgive the terrible indentation folks.... So the problem i have here is that i want to make it so while it subtracts from 2 from 40 to make it so when it hits 20 then it will start subtracting by 1 instead of 2. How can i transition to that?


#2

You can put a loop inside of a loop. I usually do while/until/for loops.


#3

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