From: Ryan Davis Date: 2012-02-07T04:35:18+09:00 Subject: Re: Easy loop question Please do your own homework On Feb 6, 2012, at 11:01, Viera Tarcova wrote: > 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 > > -- > Posted via http://www.ruby-forum.com/. >