On Feb 11, 2008, at 7:24 AM, Robert Klemme wrote:

> 2008/2/11, Ashley Wharton <ashleywnj / gmail.com>:
>> ...
>
>> With further help from Kastner:
>>
>> MAX = 100000
>>
>> def get_number(prompt = "")
>>  print prompt
>>  # ruby methods return the last value
>>  gets.to_i
>> end
>>
>> def print_from_to(start, stop)
>>  start.upto(stop) do |number|
>>    puts number
>>  end
>> end
>>
>> loop do
>>  number = get_number "Please enter a number less than #{MAX}: "
>>  next if number >= MAX
>>  print_from_to(number, MAX)
>>  break
>> end
>
> As far as I can see you logic is: read user input until it is valid
> and then print from input to MAX.  I would remove the printing from
> the loop because that is much cleaner.

I interpret Robert as saying that he prefers something like:

<code>
#! /usr/bin/env ruby -w

MAX = 100_000

def get_number(prompt = "")
    print prompt
    gets.to_i
end

def print_from_to(start, stop)
    start.upto(stop) { |number| puts number }
end

number = MAX
while number >= MAX
    number = get_number "Please enter a number less than #{MAX}: "
end
print_from_to(number, MAX)
</code>

So do I.

Regards, Morton