From: Ashley Wharton Date: 2008-02-08T07:42:47+09:00 Subject: Re: New user - very basic question ------=_Part_31314_30373297.1202424174579 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 7, 2008 5:10 PM, Benjamin Stiglitz wrote: > Not elegant, but better: > > def require_number(prompt, max) > print prompt > reply = gets.to_i > if reply >= max then reply = require_number "Please enter a number > less than #{max}: ", max end > reply > end > > require_number 'Please enter a number: ', 100 Thank you for taking the time - could I trouble you further? If I want the "reply" to iterate through until it reaches 100 could just add the "while" to your code as below? def require_number(prompt, max) print prompt reply = gets.to_i if reply >= max then reply = require_number "Please enter a number less than #{max}: ", max end while reply < max reply = reply + 1 puts reply end end require_number 'Please enter a number: ', 100 > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_31314_30373297.1202424174579--