Hello guys, this loop makes all the even numbers being divided by two

and odd numbers multiplied by three plus one.

But how would you make the loop stop when it gets to number one?

Thank you

def f n # this function calculates next number in your sequence

if n % 2 == 0 # n is even

return n / 2

else

return n * 3+1

end

end

num = gets.to_i # read in a number

while true # infinitely…

num = f(num) # find the next number

puts num # print it

sleep 1 # wait one second

end