From: ishamid Date: 2006-11-28T06:45:11+09:00 Subject: Re: simple loops and recursion > def expect(msg, expected_value) > puts "#{msg}#{expected_value}:" > loop do > actual_value = gets.chomp.to_i > return actual_value if actual_value == expected_value > puts "Sorry, expected #{expected_value} but got #{actual_value}" > end > end > > Note that this function is not perfect; it does not check to see if an > actual integer was entered, so if people enter non-digits they will be > seen as 0 values. I leave this as a exercise for the reader... Is this too naive/non-Rubyish for what you had in mind? I just moved the .to_i; it seems to work... =========== def expect(msg, expected_value) puts "#{msg}#{expected_value}:" loop do actual_value = gets.chomp return actual_value if actual_value.to_i == expected_value puts "Sorry, expected #{expected_value} but got #{actual_value}" end end expect('We want ', 98) =========== Thank you again Idris